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:
def main():
    n, m = map(int, input().split())
    count = 0

    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)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=[int(i) for i in input().split()]



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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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 == 2 or M == 2:
  ans = 0
elif N == 1 or M == 1:
  if 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())
N, M = min(N,M), max(N,M)

ans = [[1], [2, 0], [3, 0, 9], [2, 0, 6, 4]]
if M <= 4:
  print(ans[M-1][N-1])
  exit()
if N == 1:
  print(M-2)
  exit()
if N == 2:
  print(0)
  exit()
if N == 3:
  print(N*M - 6)
  exit()

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

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

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

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

n,m = MI()

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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
# input = sys.stdin.readline 
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()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

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(max(N*M-2,0))
else:
    print(max((N*M)-N*2-M*2+4,0))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

#四つ角：4回
#辺上：6回
#内側：9回
if N==1 and M==1:
    print(1)
elif N == 1 or M ==1:
    #端：2回
    #その他：3回
    print(max(N-2,M-2))
else:
    print((N-2)*(M-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())
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:
    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<=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))

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 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)
  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:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# マス目の上下左右の端が全て表になるので、マス目の総数から引けばOK ※角が重複するので-4をする
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))

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

Submission status: Accepted

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

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 = [int(x) for x in 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);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))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
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)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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