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:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


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


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


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


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


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/arc091/tasks/arc091_a
# 角に存在するのは4回→表になる
# 端にあるのは6回→表になる
# 内側に存在するカードは9回フリップする→全部裏になる
# よって答えは基本的にN-2 * M-2 ただし(N,M>=2)
# コーナーケース N and M ==1のとき→1
# N == 1のとき M-2が答え


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

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

Submission status: Accepted

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

res = 0

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

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*M-2*max(0,N-1)-2*max(0,M-1))

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/arc091/tasks/arc091_a

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

# 偶数回裏返す->表
# 奇数回裏返す->裏

# 四隅->4回->表
# 四隅以外の外枠->6回->表
# 内側->9回->裏

# 1マスの場合
if N == 1 and M == 1:
    print(1)
    exit(0)

# 1行又は1列の場合->両端以外
if N == 1 or M == 1:
    print(max(N, M)-2)
    exit(0)

# 内側のカードの枚数を求める
print((N-2)*(M-2))

Submission status: Accepted

Solution code:
#!python3

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


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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
h,w  = map(int,input().split())
if h== 1 and w == 1:
    ans = 0
    
elif h == 1 or w == 1:
    ans = 2
    
else:
    ans = 2*(h-2)+2*(w-2)+4
ans = (h*w) - ans
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())
N, M = min(N, M), max(N, M)
if M == 1:
    print(1)
elif N == 1:
    print(M-2)
else:
    print((M-2)*(N-2))

Submission status: Accepted

Solution code:
n, m = [int(x) for x in input().split()]
print(1 if n == 1 and m == 1 else m - 2 if n == 1 else n - 2 if m == 1 else (n - 2) * (m - 2))

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))
nn = min(n, m)
mm = max(n, m)

if nn == mm:
  if nn == 1:
    print(1)

  else:
    print(max(nn-2, 0) * max(mm-2, 0))
  
else:
  if n != 2:
    print(max(nn-2, 1) * max(mm-2, 1))
  else:
    print(0)

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
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)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(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 >= 3 and m >= 3:
    ans = (n-2) * (m-2)
elif n >= 3 and m==1:
    ans = n-2
elif m >= 3 and n==1:
    ans = m-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 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:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

def main():
    n, m = na()
    if n > 1:
        n -= 2
    if m > 1:
        m -= 2
    print(n * m)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def flip(a,b):
    A = max(a,b)
    B = min(a,b)

    if B >= 2:
        return (A-2) * (B-2)

    if B == 1:
        if A >= 2:
            return A-2
        elif A == 1:
            return 1

a = flip (N, M)
print(a)

Submission status: Accepted

Solution code:
H,W =[int(i) for i in input().split()]
if H*W==1:
    print(1)
elif H==1 and W!=1:
    print(max(0, W-2))
elif W==1 and H!=1:
    print(max(0, H-2))
else:
    print(max(H-2, 0)*max(W-2, 0))

Submission status: Accepted

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

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

Submission status: Accepted

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

#角
#ura += 0

#辺
if M==1 and N==1:
  ura +=1
else:
  if M*N==M or M*N==N:
    ura += max(M,N)-2
#内側
ura += max(N-2,0) *max(M-2,0)

print(ura)

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(max(n, m)-2)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
x,y=list(map(int, input().split()))

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

else:
	print(((x-2)*(y-2)))

Submission status: Accepted

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

    ans = 0
    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)
  exit(0)

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

Submission status: Accepted

Solution code:
# import bisect
from collections import Counter, defaultdict, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n, m = list(map(int,ipti().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))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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(x) for x in 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 and m == 1: ans = 1
elif n == 1 or m == 1: ans = max(n, m) - 2
else: pass
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())

ans = abs((N - 2) * (M - 2))

print(ans)

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)

NM = [int(x) for x in input().split()]
NM.sort()
N = NM[0]
M = NM[1]

if N == 1:
    if M >= 3:
        ans = M - 2
    elif M == 1:
        ans = 1
    else:
        ans = 0

    print(ans)
    exit()
elif N == 2:
    print(0)
    exit()

ans = (N - 2) * (M - 2)

print(ans)

Submission status: Accepted

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

if n == 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-2)) * (max(0,m-2)))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    def int():
        return int(sys.stdin.readline().rstrip())

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

    def map_int():
        return [int(x) for x in Scanner.string().split()]

    def string_list(n):
        return [input() for i in range(n)]

    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    def roundUp(a, b):
        return -(-a // b)

    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    def toLowerMultiple(a, x):
        return (a // x) * x

    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7


def main():
    # sys.stdin = open("sample.txt")
    N, M = Scanner.map_int()
    if N == M == 1:
        print(1)
    elif N == 1:
        print(M-2)
    elif M == 1:
        print(N-2)
    else:
        print((N-2) * (M-2))

    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def examC():
    N = LI(); N.sort()
    if N[0]==1:
        if N[1]==1:
            ans = 1
        else:
            ans = max(0,N[1]-2)
    else:
        ans = (N[1]-2)*(N[0]-2)
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examC()

"""

"""

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,M=map(int,input().split())
print(abs(((N-2)*(M-2))))

Submission status: Accepted

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

Submission status: Accepted

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

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

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 and M > 2:
    print(M - 2)
elif N > 2 and 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:
    ans = 1
elif n == 1 :
    ans = max(0,m - 2)
elif m == 1:
    ans = max(0,n - 2)
else:
    ans = (n - 2) * (m - 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:
import sys
n, m = [int(i) for i in sys.stdin.readline().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))

Submission status: Accepted

Solution code:
#2*2以上では隅:4回､辺:6回､内部:9回
#(n-2)*(m-2)

#1*mでは2333333...332となってるので(m-2)*1
#1*1では1なので1
n,m=map(int,input().split())
if n==1:
  if m==1:
    ans=1
  else:
    ans=1*(m-2)
else:
  if m==1:
    ans=(n-2)*1
  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(M - 2)
elif N != 1 and M == 1:
    print(N - 2)
elif N == 1 and M == 1:
    print(1)
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 * M - (N + M) * 2 + 4)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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


def solve(n: int, m: int):
    if n == 1 and m == 1:
        return 1
    if n >= 2 and m >= 2:
        return n * m - 2 * (n + m - 2)
    return max(n - 2, 0) + max(m - 2, 0)


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


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

Submission status: Accepted

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

if 2 <= n:
    n -= 2
if 2 <= m:
    m -= 2
    
print(n * m)

Submission status: Accepted

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

# 四隅のカードが裏を向くか
fc=(N==1 and M==1) # 4箇所のうち1箇所(自分自身)にのみカードがある場合
# 左端及び右端（四隅を含まない。）のカードが裏を向くか(N>=3)
fs=(N>=3 and M==1) # 6箇所のうち3箇所にのみカードがある場合
# 上端及び下端（四隅を含まない。）のカードが裏を向くか(M>=3)
fu=(M>=3 and N==1) # 同上
# 内部のカードが裏を向くか(N>=3 and M>=3)
fi=(M>=3 and N>=3) # N>1 and M>1のとき内部のカードは全て裏を向く。9箇所にカードがあるので

ans=(1 if fc else 0)+(N-2 if fs else 0)+(M-2 if fu else 0)+((M-2)*(N-2) if fi else 0)

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def solve():
  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)
  else:
    print((n-2)*(m-2))
solve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
if N + M == 2:
    print(1)
    exit()
if N == 2 or M == 2:
    print(0)
    exit()
print(max(1, (N-2))*max(1, (M-2)))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
if N == 1 or M == 1:
    r = max(N - 2, M - 2)
else:
    r = (N - 2) * (M - 2)

if N + M == 2:
    print(1)
else:
    print(r)

Submission status: Accepted

Solution code:
import math
import heapq
from collections import Counter

#N,K=map(int, input[].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input[].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

N,M=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
n=0
m=0
if(N!=1):
    n=2
if(M!=1):
    m=2

print(N*M-N*m-M*n+n*m)

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    print(compute(min(n, m), max(n, m)))


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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
from operator import itemgetter
import re
import sys
from itertools import accumulate
from collections import defaultdict
from collections import deque
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
input = sys.stdin.readline
N,M = 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(N+M-3)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
N, M = tuple(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((M - 2) * (N - 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-2, 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:
  print(1)
elif n == 1 or m == 1:
  print(max(n-2, m-2, 0))
else:
  print((n-2)*(m-2))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
if H==1 and W==1:
    print(1)
elif H%2==0 and W%2==0:
    print((H-2)*(W-2))
elif H%2==0 and W%2!=0:
    print(max(1,(H-2))*max(1,(W-2)))
else:
    print(H*(W-2))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#ARC091C
import copy
import sys
import math

#n = int(input())
tmp = input().split()
n,m = list(map(lambda a: int(a), tmp))

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

Submission status: Accepted

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