Problem:


Score : 300 points

Problem Statement

There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region.
The front and back sides of these cards can be distinguished, and initially every card faces up.

We will perform the following operation once for each square contains a card:

For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square.

It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed.
Find the number of cards that face down after all the operations.

Constraints

1 \leq N,M \leq 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

Print the number of cards that face down after all the operations.

Sample Input 1

2 2

Sample Output 1

0

We will flip every card in any of the four operations. Thus, after all the operations, all cards face up.

Sample Input 2

1 7

Sample Output 2

5

After all the operations, all cards except at both ends face down.

Sample Input 3

314 1592

Sample Output 3

496080



Sample input:
2 2


Sample output:
0

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# solution

import io
import sys

nim, mike = map(int,input().split())
print(abs(nim - 2) * abs(mike - 2))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
  N, M = (int(_) for _ in input().split())
  if N > 1 and M > 1:
    N = max(0, N-2)
    M = max(0, M-2)
    print(N * M)
  else:
    if N * M == 1:
      print(1)
    else:
      print(max(max(N, M)-2, 0))
  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 or m==1:
    print(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)
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())
n = min(N, M)
m = max(N, M)
if n == 1 and m == 1:
    print(1)
elif n == 1:
    print(m-2)
else:
    print(int((n-2)*(m-2)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = l()

n.sort()

if n[0] == 1:
    if n[1] == 1:
        print(1)
    else:
        print(n[1]-2)

else:
    print((n[0]-2)*(n[1]-2))

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

Submission status: Accepted

Solution code:
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
DP2 = lambda d1, d2: [[INIT_VAL]*d2 for _ in range(d1)]
DP3 = lambda d1, d2, d3: [[[INIT_VAL]*d3 for _ in range(d2)] for _ in range(d1)]

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
shape = list(map(int, input().split()))
shape.sort()
N, M = shape
# print(N, M)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc090/tasks/arc091_a
# 15:17-15:26 done


def main():
    n, m = map(int, input().split())

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


print(main())

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
mx = max(n,m)
mn = min(n,m)

if mn == 1:
    if mx == 1:
        print(1)
    else:
        print(mx - 2)
elif mn >= 2:
    print((mx - 2) * (mn - 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:
import sys

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

def main():
    res = abs(m - 2) if n == 1 else (n - 2) * (m - 2)
    print(res)

if __name__ ==  '__main__':
    main()

Submission status: Accepted

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


def solve(N: int, M: int):
    print(abs(N - 2) * abs(M - 2))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,m = readInts()
    """
    N <= M
    N = 1かつ、M = 1のとき、1枚だけあるカードは1毎裏返されるので、答えは1でｓ。
    N = 1かつ M ≠ 1のとき、 M 枚のカードのうち両端のカードは2回、それ以外のカードは
    3回裏替えされるので、答えはM-2
    N >= 2のとき、 N <= M より M >= 2で、このとき、
    ・四隅のカードは4回、　# 表になる
    ・それ以外のカードは週上のカードは6回 # 表になる
    ・それ以外のカードは9回
    裏返されるので、答えは、(N-2)(M-2)
    """

    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))
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(10000)
def resolve():
    N, M = list(map(int, input().split(" ")))
    if N == 1 and M == 1:
        print("1")
    elif N == 1:
        print(M-2)
    elif M == 1:
        print(N-2)
    else:
        print((M-2)*(N-2))

if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
if n==m==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())
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():
    B = input()
    B = B.split()
    B = [int(i) for i in B]
    n = B[0]
    m = B[1]
    if m * n == 0:
        return 0
    if min(n, m) == 1:
        if max(n, m) == 1:
            return 1
        else:
            return max(n, m) - 2
    else:
        nc = n - 2
        mc = m - 2
        return nc * mc
          
print(main())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
url = "https://atcoder.jp/contests/abc090/tasks/arc091_a"
import copy
def main():
    tate, yoko = list(map(int, input().split()))
    count = 0
    if tate == 1 and yoko == 1:
        print("1")
        exit()
    elif tate == 1:
        print(yoko - 2)
        exit()
    elif yoko == 1:
        print(tate - 2)
        exit()
    count += (yoko - 2) * (tate - 2)
    print(count)




if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import copy
import time


line1 = str(input()).split(" ")

for index in range(len(line1)):
    line1[index] = int(line1[index])
if (line1[1] > 1 and line1[0] > 1):
    print( line1[0]*line1[1] - (2*line1[1] + 2*(line1[0]-2)))
elif (line1[1] == 1 and line1[0] == 1):
    print(1)
elif (line1[1] == 0 or line1[1] == 0):
    print(0)
else:
    print(line1[0]*line1[1] - 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())
min_value = min(n, m)
max_value = max(n, m)
ans = 0
if min_value == 1:
    if max_value == 1:
        ans = 1
    elif max_value == 2:
        ans = 0
    else:
        ans = max_value - 2
elif min_value == 2:
    ans = 0
else:
    ans = (min_value-2)*(max_value-2)

print(ans)

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

Solution code:
#

N, M = list(map(int,input().split()))
if N == 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:
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(abs(N - 2) * abs(M - 2))

Submission status: Accepted

Solution code:
N, M = [int(x) for x in input().split()]
def sol(N,M):
  if N==0 or M==0:
      return 0
  elif N==1 or M==1:
    return abs(abs(N-M)-1)
  x = (abs(3-N)+1)*(M-2)
  y = (abs(3-M)+1)*abs((N-2))
  return min(x,y)

print(sol(N,M))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

    print(ans)

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

Submission status: Accepted

Solution code:
from sys import stdin

N, M = map(int, stdin.readline().split())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

Submission status: Accepted

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

# Initially, all cards face up.
# Given that N,M >= 0.
# Let N <= M.
# Ultimately:
#   if N,M==1:      singular card will flip.
#   elif N==1:      interior cards will flip (interior to line).
#   else N,M > 1:   interior cards will flip (interior to area).

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

# Ensuring N <= M
if N > M:
    M,N = N,M

# Requires N <= M:
def numflips(N,M):
    if N==0: return 0
    if N==1:
        if M==1: return 1
        return (M-2)
    return (N-2)*(M-2)

ans = numflips(N,M)
print(ans)

Submission status: Accepted

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

if n*w==1:
    print(1)
elif n==1:
    print(w-2)
elif w==1:
    print(n-2)
elif n==2 or w==2:
    print(0)
else:
    print((n-2)*(w-2))

Submission status: Accepted

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

ans = 0


if n >= 3 and m >= 3:
    ans = (n-2) * (m-2)
    print(ans)

elif (n == 2 and m >= 3) or (m == 2 and n >= 3):
    ans = 0
    print(ans)

elif (n == 1 and m >= 3) or (m == 1 and n >= 3):
    ans = n * m - 2
    print(ans)

elif n == 2 and m == 2:
    ans = 0
    print(ans)
    
elif n == 1 and m == 1:
    ans = 1
    print(ans)
    
else:
    ans = 0
    print(ans)

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

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

Submission status: Accepted

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

resolve()

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)
        exit()
    else:
        M -= 2
else:
    N -= 2
    M -= 2

print(N * M)

Submission status: Accepted

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

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def find_gcd(list_l):
    x = reduce(gcd, list_l)
    return x


def main():
    n,m = map(int,input().strip().split()) # nは行数 # mは列数
    if n>=2 and m>=2:
        print((n-2)*(m-2))
    elif n==1 and m==1:
        print(1)
    else:
        print(n*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((m-2)*(n-2))

Submission status: Accepted

Solution code:
n, m = [int(i) for i in 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 min(n, m) == 1:
    print(max(n,m)-2)
else:
    print((n-2) * (m-2))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input().split(" ")
N = int(S[0])
M = int(S[1])

def calculate(n,m):

    if n == 1 and m == 1:
        return 1

    if n == 1:
        return m - 2

    if m == 1:
        return n - 2

    return (n - 2) * (m - 2)
result = calculate(N,M)
print(result)

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+4-2*N-2*M)

Submission status: Accepted

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


if __name__ == '__main__':
    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((m-2)*(n-2))

Submission status: Accepted

Solution code:
n,m=map(int,input().split());print([(n-2)*(m-2),n*m-2,1][(n<2)+(m<2)])

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#pypyは内包表記使わない
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

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



if __name__ == '__main__':
    main()

Submission status: Accepted

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

# N,Mどちらかが1の時はとりあえず考えない
if N == 1 and M == 1:
  ans = 1
elif N == 1 or M == 1:
  ans -= 2 
else:
  # 四隅,境界線は正なので引く
  ans -= (N*2 + M*2 - 4)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

if n==1 or m==1:
    print(max(n,m)-2)
else:
    print(max(0, total -((n+m)*2-4)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def c(n):
    if n == 1:
        return n
    elif n == 2:
        return 0
    else:
        return n-2

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

Submission status: Accepted

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

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 STR(): return input()
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 = sys.maxsize
mod = 10 ** 9 + 7

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

Submission status: Accepted

Solution code:
w, h = map(int, input().split())
 
count = 0
 
if w == h == 1:
    count = 1
elif w == 1 or h == 1:
    count = max(w,h)-2
else:
    count = (w - 2) * (h - 2)
    
print(count)

Submission status: Accepted

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


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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
l=[N,M]
l.sort()
buf=0
f=0
c=0
if l[0]==1:
    if l[1]==1:
        print("1")
    else:
        print(l[1]-2)
else:   #l[0]>1
    print((l[0]-2)*(l[1]-2))

Submission status: Accepted

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

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

if N <= 2 and M <= 2 or N == 2 or M == 2:
  print(0)
  exit()

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

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

Submission status: Accepted

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

Submission status: Accepted

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


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

if n==2 or m==2:
  print(0)
  exit()

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

Submission status: Accepted

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

Submission status: Accepted

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

#上端・下端　(n-2)*2枚のカードは、必ず裏
#４隅　4枚のカードは、必ず裏
#左端・右端　(m-2)*2枚のカードは、必ず裏
#これらの条件が強い

#中央 (n-2)*(m-2)枚のカードは、表

#1行か1列のときは、両端が裏、内側が表

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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