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:
H,W=map(int,input().split())
print(abs((H-2)*(W-2)))

Submission status: Accepted

Solution code:
H,W=map(int,input().split())

ans=0       # 裏の数

# 1*1
if H==1 and W==1:
    ans+=1

# 4隅以外の端
if W<2 and H>=3:
    ans+=(H-2)
if H<2 and W>=3:
    ans+=(W-2)

# 上記以外
if H>=3 and W>=3:
    ans+=(H-2)*(W-2)

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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())
print(n*m-2*(n+m)+4 if n!=1 and m!=1 else max(n*m-2,1))

Submission status: Accepted

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

Submission status: Accepted

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

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


class Solution:
    def solve(self, N: int, M: int) -> int:

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


if __name__ == '__main__':

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

    # solve
    solution = Solution()
    ans = solution.solve(N, M)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N_gyou, M_retu = map(int, input().split())

if (N_gyou == 2 or M_retu == 2):
    ans = 0
elif (N_gyou == 1 and M_retu == 1):
    ans = 1
elif (N_gyou == 1):
    ans = M_retu - 2
elif (M_retu == 1):
    ans = N_gyou - 2
else:
    ans = (N_gyou - 2) * (M_retu - 2)

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
H,W = map(int, input().split())
h_ = (1 if H==1 else (0 if H == 2 else H-2))
w_ = (1 if W==1 else (0 if W == 2 else W-2))
ret = h_*w_
print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ans = (n-2)*(m-2)
print(abs(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:
# 角のマスは4回、端のマスは6回（表になる）
# それ以外のマスであればカードを裏返す回数は9回（裏になる）
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 - 2*((n-1)+(m-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:
    print(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:
    ans=1
elif n==1 or m==1:
    ans=max(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())
if n < 2:
    n = 3
if m < 2:
    m = 3
ans = (n-2)*(m-2)
if ans < 0:
    ans = 0
print(ans)

Submission status: Accepted

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

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

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 = [int(n) for n in input().split()]

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

Submission status: Accepted

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

n = 1 if n < 2 else n - 2
m = 1 if m < 2 else m - 2

print(n * m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = sorted(map(int, input().split()))
print(0 if 2 in [N, M] else abs(M - 2) if N == 1 else (N - 2) * (M - 2))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#coding: utf-8

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

Submission status: Accepted

Solution code:
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce

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:
    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())
answer = 0
if N == 1 and M == 1:
    answer = 1
elif N == 1 and M != 1:
    answer = max(0, M-2)
elif N != 1 and M == 1:
    answer = max(0, N-2)
elif M >= 2 and N >= 2:
    answer = (M-2) * (N-2)

print(answer)

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:
  c = max(0, m-2)
  d = max(c, n-2)
  print(d)
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:
def main():
    width, height = map(int, input().split(" "))
    if width * height == 1:
        print(1)
    elif width == 1:
        print(height - 2)
    elif height == 1:
        print(width - 2)
    else:
        print((height - 2) * (width - 2))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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:
n,w=map(int,input().split())
print(abs(n*w-n*2-w*2+4))

Submission status: Accepted

Solution code:
import sys

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

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

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

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

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
n = min(a, b)

m = max(a, b)

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
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))


#A = [[0] * W for i in range(H)]
#C = ["o" * W for i in range(H)] 
#C = ["#"*(W+2)] + ["#"+C[i]+"#" for i in range(H)] + ["#"*(W+2)]
#dx = [1, 1, 0, -1, -1, -1, 0, 1]
#dy = [0, 1, 1, 1, 0, -1, -1, -1]
#
#for h in range(H):
#    for w in range(W):
#        for i in range(8):
#            if C[h+1+dx[i]][w+1+dy[i]] == "o":
#                A[h][w] += 1
#ans = 0
#for h in range(H):
#    for w in range(W):
#        if A[h][w] % 2 == 0:
#            ans += 1
#
#print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# N, Mが十分に大きい時
# 頂点: 4
# 端: 6
# それ以外: 9
# ひっくり返る
# はじめ表なので
# 頂点: 4 -> 表
# 端: 6 -> 表
# それ以外: 9 -> 裏
# となる。
# N, Mが小さい時は場合分けする必要がある
# NかMのどちらかだけが1のとき
# 頂点: 2 -> 表
# 端: 3 -> 裏
# それ以外: 3 -> 裏
# NかMのどちらかだけが2のとき
# 頂点: 4 -> 表
# 端: 6 -> 表
# それ以外: 6 -> 表
# NかMのどちらも1のとき
# 頂点: 1 -> 裏
# 端: 1 -> 裏
# それ以外: 1 -> 裏

# 頂点: max(N, 2) * max(M, 2)
# # 端(N>=3): min((N - 1) * (M), 6)

N, M = map(int, input().split())
N, M = max(N, M), min(N, M)
if N >= 3 and M >= 3:
    ans = N * M - (2 * N + 2 * M - 4)
    print(ans)
    exit()

if N >= 3 and M == 2:
    print(0)
    exit()

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

if N == 2:
    print(0)
    exit()

if N == 1 and M == 1:
    print(1)
    exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
ans = N*M
if N==1 and M==1:
    print(1)
    exit()
if N < 3 and M < 3:
    print(0)
    exit()
#偶数回操作が行われるもの
even = 0
#奇数回操作が行われるもの
odd = 0
#答えはoddの値
if N<=M:
    if N==1:
        s = 2*N
        print(ans-s)
    else:
        s = 2*N+2*(M-2)
        print(ans-s)
else:
    if M==1:
        s = 2*M
        print(ans-s)
    else:
        s = 2*M+2*(N-2)
        print(ans-s)

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

Submission status: Accepted

Solution code:
def solve(n, m):
    return abs(n * m - 2 * n - 2 * (m - 2))

_n, _m = map(int, input().split())
print(solve(_n, _m))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
# print(NM)
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 or M >= 2:
    print((N-2)*(M-2))

Submission status: Accepted

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


main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#n = int(input())
#s = input()
n,m = map(int,input().split())
#da = list(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:
def main():
    N,M = map(int,input().split())
    if N == 1 or M == 1:
        if N == M:
            print(1)
        else:
            print(N*M-2)
    else:
        print(N*M-2*(N+M-2))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
cnt = 0
if n == 1 and m == 1:
  corner = 0
  wall = 0
if n > 1 and m > 1:
  corner = 4
  wall = max(0, n-2) * 2 + max(0, m-2) * 2
if n == 1 and m > 1:
  corner = 2
  wall = 0
if n > 1 and m == 1:
  corner = 2
  wall = 0
print(n * m - corner - wall)

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

print(N*M)

Submission status: Accepted

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

ans = 0
if n == 1:
    if m == 1:
        ans = 1
    elif m == 2:
        ans = 0
    else:
        ans = m - 2

if n == 2:
    ans = 0

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



print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    N, M = [int(x) for x in input().split()]
    if N >= 2 and M >= 2:
        print((N - 2) * (M - 2))
    else:
        if N == 1 == M:
            print(1)
        else:
            print(max(N, M) - 2)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

"""
# An experiment
n_count_map = [[0 for _ in range(M)] for _ in range(N)]


def update(x, y):
    # Count
    n_count_map[y][x] += 1
    if y + 1 < N:
        n_count_map[y + 1][x] += 1
    if y - 1 >= 0:
        n_count_map[y - 1][x] += 1
    if x + 1 < M:
        n_count_map[y][x + 1] += 1
    if x - 1 >= 0:
        n_count_map[y][x - 1] += 1
    if y + 1 < N and x + 1 < M:
        n_count_map[y + 1][x + 1] += 1
    if y - 1 >= 0 and x - 1 >= 0:
        n_count_map[y - 1][x - 1] += 1
    if y + 1 < N and x - 1 >= 0:
        n_count_map[y + 1][x - 1] += 1
    if y - 1 >= 0 and x + 1 < M:
        n_count_map[y - 1][x + 1] += 1


for n in range(N):
    for m in range(M):
        update(m, n)

print(n_count_map)
"""

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    if n > m:
        n, m = m, n

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


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

Submission status: Accepted

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

Submission status: Accepted

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

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:
N,M = map(int,input().split())
"""
mat = [[0]*M for _ in range(N)]
dx = [-1,0,1,-1,0,1,-1,0,1]
dy = [1,1,1,0,0,0,-1,-1,-1]
for i in range(N):
    for j in range(M):
        for k in range(9):
            if 0 <= i+dy[k] <= (N-1) and 0 <= j+dx[k] <= (M-1):
                mat[i+dy[k]][j+dx[k]] += 1
print(mat)
"""
if N == M == 1:
    print(1)
elif N == 1 or M == 1:
    print(N*M-2)
else:
    print(N*M-2*(N+M-2))

Submission status: Accepted

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

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

Submission status: Accepted

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

if n>=2 and m>=2:
    n-=2
    m-=2
    print(n*m)
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())
answer = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N,M=map(int,input().split())
if N==2 or M==2:
    print(0)
    exit()
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 == 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:
N, M = map(int, input().split())

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

Submission status: Accepted

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

# N <= M としても一般性を失わない
if N == 1:
    if M == 1:
        print(1)
    elif M == 2:
        print(0)
    else:
        print(M-2)
elif N == 2:
    print(0)
else:
    print((N-2)*(M-2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

n,m = map(int, input().split())
ans = n*m
n,m = min(n,m), max(n,m)

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

tmp = n + m - 2
print(ans - tmp * 2)

Submission status: Accepted

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


def solve(N: int, M: int):
    if N == 1 and M == 1:
        print(1)
        return 

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


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:
a = list(map(int, input().split()))
if a[0]==1 and a[1]==1:
    print(1)
    exit()
if a[0]==1 or a[1]==1:
    print(max(max(a)-2, 0))
    exit()
print((a[0]-2)*(a[1]-2))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

ANS = 0
if N != 1 and M != 1:
  ANS = N * M - (2 * N + 2 * M -4)
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())
ans = n * m
if n == 1 and m == 1:
    pass
elif n == 1 or m == 1:
    ans -= 2
else:
    ans -= 2 * (n + m) - 4
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
if n>m: m,n=n,m
print(m-2 if n==1 and m>1 else 1 if n==1 else (n-2)*(m-2))
#四隅は4回,その他の端は6回,その他は9回ひっくり返るので(n-2)*(m-2)

Submission status: Accepted

Solution code:
import sys

n, m = map(int, sys.stdin.readline().split())
if n > m:
    n, m = m, n

def main():
    if n == 1:
        if m == 1:
            return 1
        else:
            return m - 2
    else:
        return (n - 2) * (m - 2)
        
if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
# あるマスの接する面・点の数が偶数の時、そのマスは裏になる
N,M = list(map(int, input().split()))

# 四隅でも外周でも無い内側のマス
if N == 1 or M == 1:
    print(abs(N * M - 2))
else:
    print(N * M - (4 + (N - 2) * 2 + (M - 2) * 2))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 一般に偶奇のパリティで解ける
# 接するカードの数が奇数ならそのカードは表に偶数なら裏になる
# つまり接するカードの数が偶数となるカードを数え上げればよい
n,m = map(int,input().split())
# 3行3列以上の場合
# 全体 - (行の外枠) - (列の外枠) + 4(引きすぎた4隅を足す)
# さらに考察すると下になる
# 全体(n * m) - (2 * 列の数) - (行の数 * 2) + 4
if n >= 3 and m >= 3:
  print(n * m - (2 * m) - (n * 2) + 4)
elif n == 1 and m == 1:
  print(1)
# 1行の場合は両端のカード以外は偶数のカードと接するので列数 - 2が解
elif n == 1:
  print(m - 2)
# 2行の場合は全てのカードが奇数のカードと接するので答えは0
elif n == 2:
  print(0)
elif n >= 3 and m == 1:
  print(n - 2)
elif n >= 3 and m == 2:
  print(0)

Submission status: Accepted

Solution code:
def flip(x):
	if x:
		return False
	else:
		return True


n, m = [int(el) for el in input().split(' ')]

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
nums=list(map(int, input().split()))
nums.sort()
if nums[0]==1:
  if nums[1]==1:
    print(1)
  else:
    print(nums[1]-2)
elif nums[0]==2:
  print(0)
else:
  print((nums[0]-2)*(nums[1]-2))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

n,m = list(map(int,input().split()))
#n=1 もしくは m=1の時とその他の時を分けて考える
ret = 0
if n==1:
    if m==1:
        ret=1
    else:
        ret=m-2
else:
    #n>=2
    if m==1:
        ret=n-2
    else:
        ret=(n-2)*(m-2)
print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

if n>2 and m>2:
      print((n-2)*(m-2))
      exit()
if n==2 or m==2:
      print(0)
      exit()
if n==1 and m>2:
      print(m-2)
      exit()
if n>2 and m==1:
      print(n-2)
      exit()
if n==1 and m==1:
      print(1)
      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)
else:
    print(N*M - 2*(N+M-2))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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