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(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n,m=mii()

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

'''
if N > 3 and M > 3:
    ans = N * M - 2*N - 2*M + 4
    print(ans)
'''

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

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)



n,m=l()
if(n>m):
    n,m=m,n
if(n==1 and m==1):
    print(1)
    exit()
if(n==1 and m!=1):
    print(m-2)
    exit()
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:
	print(m - 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 * M - 2 * N - 2 * M + 4)

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

ret = 0

if (n >= 3) and (m >= 3):
    ret += (n-2) * (m-2)

if (n == 1) and (m >= 3):
    ret += m - 2

if (m == 1) and (n >= 3):
    ret += n - 2

if (m == 1) and (n == 1):
    ret += 1

print(ret)

Submission status: Accepted

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

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

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    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:
        S = max(N, M)
        ans = max(0, S-2)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
import collections

def main():
    x, y = input_list()
    if x < 2 or y < 2:
        print(abs(x-2) * abs(y-2))
    else:
        print((x-2) * (y-2))


def yogen(a, b, angle):
    coss = math.cos((angle/180)*math.pi)
    return math.sqrt(a**2 + b**2 - 2*a*b*coss)


def get_angle(hour, minute):
    h = (hour * 360) / 12 + (minute * 360) / (12 * 60)
    m = (minute * 360) / 60
    angle = abs(h-m)
    return min(angle, 360-angle)

def has(v, l):
    for vl in l:
        if v == vl:
            return True
    return False

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    IN = [int(_) for _ in input().split()]
    N = IN[0]
    M = IN[1]

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

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



if __name__ == '__main__':
    main()

Submission status: Accepted

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

def resolve():
    n,m=map(int, input().split())
    if n==1 and m==1:
        ans=1
    # n,m=1,1を除外してるからどっちか１だったら他方の-2でok
    elif m==1 or n==1:
        ans=max(n,m)-2
    else:
        ans=(n-2)*(m-2)
    print(ans)
resolve()

Submission status: Accepted

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

def resolve():
    n,m=map(int, input().split())
    if n==1 and m==1:
        ans=1
    # n,m=1,1を除外してるからどっちか１だったら他方の-2でok
    elif m==1:
        ans=n-2
    elif n==1:
        ans=m-2
    else:
        ans=(n-2)*(m-2)
    print(ans)
resolve()

Submission status: Accepted

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

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

Submission status: Accepted

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

if N==1 and M==1:
    result=1

elif N==1:
    result=M-2

elif M==1:
    result=N-2

else:
    result=(M-2)*(N-2)

print(result)

Submission status: Accepted

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

n = min(N,M)
m = max(N,M)

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

n = min(N,M)
m = max(N,M)

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

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

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 標準入力の取得
N, M = list(map(int, input().split()))
N, M = min(N, M), max(N, M)  # N <= Mとしても一般性は失われない


def main() -> None:
    """Entry point
    """
    # 求解処理
    """
    各カードが奇数回または偶数回裏返されるかを考える。
    """
    result = 0
    if N == 1:
        if M == 1:
            result = 1
        else:
            result = M - 2
    else:
        result = (N - 2) * (M - 2)

    # 結果出力
    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 標準入力の取得
N, M = list(map(int, input().split()))
N, M = min(N, M), max(N, M)

# 求解処理
N, M = min(N, M), max(N, M)
result = 0
if N == 1:
    if M == 1:
        result = 1
    else:
        result = M - 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)
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:
    ans = max(max(n,m)-2,1)
else:
    ans = (n-2)*(m-2)
print(ans)

Submission status: Accepted

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

if n==1 or m==1:
    ans = max(max(n,m)-2,1)
else:
    ans = (n-2)*(m-2)
print(ans)
'''
input_map = [[1 for i in range(m)]for j in range(n)]

def checker(input_map,x,y):
    if 0<=x<=m-1 and 0<=y<=n-1:
        input_map[y][x]*=-1
    return input_map

check_li = [[0,0],[0,1],[1,0],[1,1],[-1,0],[0,-1],[-1,-1],[-1,1],[1,-1]]
for i in range(n):
    for j in range(m):
        for c in check_li:
            input_map = checker(input_map,j+c[0],i+c[1])

ans=0
for i in range(n):
    for j in range(m):
        if input_map[i][j]==-1:
            ans+=1
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:
n,m=map(int,input().split())
if n==2 or m==2:
    print(0)
elif 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:
h,w = map(int,input().split(" "))
if h == 1 and w == 1:
    print(1)
elif h == 1:
    print(w - 2)
elif w == 1:
    print(h - 2)
else:
    print((h - 2) * (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(n*m-2)
else:
    print((m-2)*(n-2))

Submission status: Accepted

Solution code:
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions

import copy

# import heapq
# from collections import deque
# import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

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


# ===CODE===

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

    if n > 2 and m > 2:
        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 - 2, m - 2)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import os

def file_input():
    f = open('ARC091/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    # int(input())
    N,M=map(int, input().split())

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, m = sorted(map(int, input().split()))
print(1 if n==m==1 else m-2 if n==1 else (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)
else:
    print(max(N - 2, M - 2, 1))

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
from collections import defaultdict

import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n,m=mis()
    ans=n*m
    cnt=0
    if n>1:
        ans-=2*m
        cnt+=1
    if m>1:
        ans-=2*n
        cnt+=1
    if cnt==2: ans+=4
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''

    N, M = [int(item) for item in input().split()]
    res_dict = {0:0, 1:0, 2:0, 3:0, 5:0, 8:0}

    if N > M:
        N, M = M, N
    
    if N == 1:
        if M >= 2:
            res_dict[1] = 2
            res_dict[2] = M -2
        else:
            res_dict[0] = 1
    else:
        res_dict[3] = 4
        res_dict[5] = 2* (N - 2 + M - 2)
        res_dict[8] = M*N - (2*(N+M) -4)
    
    # print(res_dict)
    cnt = 0
    for i, v in res_dict.items():
        if i % 2 == 0:
            cnt += v

    print(cnt)            


if __name__ == "__main__":
    resolve()

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:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,m = iim()

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:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7



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

total = N * M

sumi = 4
if N >= 2 and M >= 2:
    hen = (N-2) * 2 + (M-2) * 2
    ans = total - sumi - hen
elif N == 1 and M > 1:
    hen = M-2
    ans = hen
elif N > 1 and M == 1:
    hen = N - 2
    ans = hen
else:
    ans = 1


print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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


def log(*args):
    print(*args, file=sys.stderr)


N, M = map(int, input().split())
if N == 1 and M == 1:
    print(1)
    exit(0)
# Nは1じゃない状態
elif N == 1:
    N, M = M, N
if M == 1:
    print(N - 2)
    exit(0)

corner = 4
edge = (N - 2) * 2 + (M - 2) * 2

print(N * M - corner - edge)

Submission status: Accepted

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

Submission status: Accepted

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

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

    if N == 2 or M == 2:
        print(0)
        return

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

    ans = abs(0*4 + 0*(n-2)*2 + 0*(m-2)*2 + 1*(n-2)*(m-2))

    return ans

print(solve())

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:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int):
    if N > 2 and M > 2:
        print((N-2) * (M-2))
        return
    if N == 1 and M == 1:
        print(1)
        return
    if N == 1 and M >= 2:
        print(M-2)
        return
    if N >= 2 and M == 1:
        print(N-2)
        return
    print(0)
    return


# Generated by 1.1.6 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:
def main():
    N, M = map(int, input().split())

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

    if (N, M) == (1, 1):
        print(1)
        return

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

    def judge(r, c):
        if r >= N or c >= M:
            return 0

        if ~memo[r][c]:
            return 0

        ux = (r == 0)  # 上がない
        bx = (r == N - 1)  # 下がない
        lx = (c == 0)  # 左がない
        rx = (c == M - 1)  # 右がない

        ret = 9  # マスと周囲がすべて存在するときの反転回数
        ret -= (ux + bx + lx + rx) * 3 - (ux & lx) - (ux & rx) - (bx & lx) - (bx & rx)
        return ret & 1  # 奇数回反転->裏向き

    memo = [[-1] * 2 for _ in range(2)]
    # gridの左上の2x2マスの反転判定

    for r in range(2):
        for c in range(2):
            memo[r][c] = judge(r=r, c=c)

    ans = memo[0][0] + memo[1][0] * (N - 2) + memo[0][1] * (M - 2) + memo[1][1] * (N - 2) * (M - 2)

    # print(*memo, sep='\n')
    print(ans)


if __name__ == '__main__':
    main()

# (0,0)
# (1...N-2,0)
# (N-1,0)

# (0,1...M-2)
# (1...N-2,1...M-2)
# (N-1,1...M-2)

# (0,M-1)
# (1...N-2,M-1)
# (N-1,M-1)

Submission status: Accepted

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

if n > 1 or m > 1:
    if n >= 2 and m >= 2:
        ans -= 4
    else:
        ans -= 2

if n > 1:
    ans -= max((m - 2) * 2, 0)

if m > 1:
    ans -= max((n - 2) * 2, 0)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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



if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
c=n*m
if c==1:
    print(1)
elif n==1 or m==1:
    print(c-2)
else:
    print(c-n*2-(m-2)*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:
n,k=map(int, input().split())
print(abs((n-2)*(k-2)))

Submission status: Accepted

Solution code:

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

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

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:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N,M=map(int,readline().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))
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*m-(2*n+2*m-4))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

def solve(N,M):
    if N==1 and M==1:
        return 1
    if N==1:
        return M-2
    if M==1:
        return N-2
    ans = (N-2)*(M-2)
    return ans
print(solve(N,M))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    # 隣接するカードの枚数が奇数の時は，偶数回ひっくり返されるので表になる
    # 偶数の時は，奇数回ひっくり返されるので，裏になる．これをカウントしたい．
    # 真ん中のカードは裏になる．
    if n > m:
        n, m = m, n
    # nのほうが小さい
    if n == 1 and m == 1:
        print(1)
    elif n == 1:
        print(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 and m!=1:
  print(m-2)
elif m==1 and n!=1: 
  print(n-2)
elif n==2:
  print(0)
elif n>3:
  print((m-2)*(n-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()
answer = abs((N-2) * (M-2))
print(answer)

Submission status: Accepted

Solution code:
def main():
    N, M = (int(i) for i in 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:
        h = N-2
        w = M-2
        ans = h*w
    print(ans)


if __name__ == '__main__':
    main()