Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

1 \leq N,M \leq 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

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

Sample Input 1

2 2

Sample Output 1

0

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

Sample Input 2

1 7

Sample Output 2

5

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

Sample Input 3

314 1592

Sample Output 3

496080



Sample input:
2 2


Sample output:
0

Submission status: Accepted

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

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


def main():
    if N - 2 < 0 or M - 2 < 0:
        print(max(1, N - 2) * max(1, M - 2))
    else:
        print((N - 2) * (M - 2))

    return


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 各マス自身とその周囲のぶんだけ変わるので,
# 周囲を1マスずつ取り除いたときに残っている部分は9回訪れることになる
# 端は4回、それ以外の外周は6回
# 裏->表->裏を繰り返すので奇数回訪れた場所を数える
# どちらも1 or いずれかが1の場合だけ気をつける

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

Submission status: Accepted

Solution code:
n,m=[int(i) for i in input().split()]
print(abs(n-2)*abs(m-2))

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

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def flip_flip_and_flip(N: int, M: int) -> int:
    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)


if __name__ == "__main__":
    N, M = map(int, input().split())
    ans = flip_flip_and_flip(N, M)
    print(ans)

Submission status: Accepted

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

def f():
    if n == 1 and m == 1:
        return 1
    if n == 1 or m == 1:
        return max(n,m)-2
    return n*m - 2*n - 2*m + 4

print(f())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=[int(i) for i in input().split()]
#print(a,b)
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())

# 1の場合
# 2の場合
# 3以上の場合
#  最外でない場合は、9回処理されるので裏返る
#  最外でコーナーの場合は、4回処理されるのでそのまま
#  最外でコーナー以外の場合は、6回処理されるのでそのまま

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

Submission status: Accepted

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

Submission status: Accepted

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

import itertools
import collections
import bisect

def main():
    N, M = map(int, input().split())
    if N > 1 and M > 1:
        print((N-2)*(M-2))
    else:
        if N == 1 and M == 1:
            print(1)
        else:
            print(max(N, M) - 2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
N = a[0]
M = a[1]
if N == 1 and M == 1:
    print("1")
elif N == 1 and M >= 2:
    print(str(M-2))
elif N >= 2 and M == 1:
    print(str(N-2))
else:
    print(str((N-2)*(M-2)))

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    X, Y = max(N, M), min(N, M)
    if X == 1:
        print(1)
    elif Y == 1:
        print(X-2)
    else:
        print((X-2)*(Y-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 min(n,m)==1:
    print(max(n,m)-2)
elif min(n,m)==2:
    print(0)
else:
    print(n*m-4-(n-2)*2-(m-2)*2)

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    if N == 2 or M == 2:
        print(0)
    else:
        print(max(1, N-2) * max(1, M-2))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


main()

Submission status: Accepted

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

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

Submission status: Accepted

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))

N,M=rl()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if N == 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())

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

def input_numbers():
    temp = list(map(int, input().split()))
    return temp

def GCD(a, b):
    if(a < b):
        temp = a
        a = b
        b = temp
    a = a % b
    if(a == 0):
        return b
    else:
        return GCD(a, b)

numbers = input_numbers()

numbers.sort()
if(numbers[0] == 1):
    if(numbers[1] == 1):
        print(1)
    else:
        print(numbers[1] - 2)

else:
    ans = numbers[0] * numbers[1] - (numbers[0] + numbers[1] - 2) * 2

    print(ans)

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n,m=map(int, input().split())
if n==1:
    if m==1:
        print(1)
    else:
        print(m-2)
elif m == 1:
    print(n-2)
else:
    print(n*m-(2*n+2*m-4))

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

Submission status: Accepted

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

print(res)

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())
print(abs(N*M - (N+M-2)*2))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a, b = [int(x) for x in input().split(" ")]
print(abs((a-2)*(b-2)))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def solve(N, M):
    if N > 2 and M > 2:
        return (N - 2) * (M - 2)
    if N == 2 or M == 2:
        return 0
    if N == 1 and M == 1:
        return 1
    return max(max(N, M) - 2, 0)


if __name__ == "__main__":
    N, M = tuple(map(int, input().split(" ")))
    print(solve(N, M))

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)
    exit(0)
  else:
    m = max(N,M)
    if m == 2:
      print(0)
      exit(0)
    else :
      print(m-2)
      exit(0)
print((N-2)*(M-2))
exit(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if N<M:
    N,M = M,N

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

print(ans)

Submission status: Accepted

Solution code:
N,M = (int(i) for i in input().split())

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

if(a == 1 or b == 1):
    if(a == 1 and b == 1):
        print(1)
    else:
        print(a*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)
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 = (int(i) for i in input().split())
(n,m) = sorted([n,m])
if n ==2 or m == 2:
  ans = 0
elif n == 1 and m > 2:
  ans = m-2
elif n == 1 and m == 1:
  ans = 1
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 == m == 1:
    print(1)
else:
    print(max(n,m)-2)

Submission status: Accepted

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

def main():
    s = input().split()
    N, M = int(s[0]), int(s[1])

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

    print(t)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
n_row = N - 2 if N != 1 else 1
n_col = M - 2 if M != 1 else 1

print(n_row * n_col)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
if n == 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:
h, w = map(int, input().split())

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ans = 0
if N == 1 and M == 1:
    ans = 1
elif N == 1 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().strip().split())

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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


abc090_c()

Submission status: Accepted

Solution code:
def main() :
    N,M = [int(i) for i in input().split()]

    if (N > 2) :
        rows = N-2
    elif (N == 1) :
        rows = 1
    else :
        print("0")
        return
    
    if (M > 2) :
        cols = M-2
    elif (M == 1):
        cols = 1
    else :
        print("0")
        return

    print(rows * cols)

main()

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:
# Flip, Flip, and Flip......
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:
a,b = map(int,input().split(" "))
if a == 2 or b == 2:
    print(0)
elif a == 1 and b == 1:
    print(1)
elif a == 1 or b == 1:
    print(a * b - 2)
else:
    print(a * b - ((a + b) * 2 - 4))

Submission status: Accepted

Solution code:
li = list(map(int,input().split()))
li.sort()
N = li[0]
M = li[1]

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, M = sorted([int(_) for _ in input().split()])
if N == 1:
    if M == 1:
        print(1)
    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==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:
# encoding: utf-8
N, M = map(int, input().split())

if N == M == 1: ans = 1
elif N == 1: ans = M - 2 # 2 corners are omitted
elif M == 1: ans = N - 2 # 2 corners are omitted
else: ans = (N - 2) * (M - 2) # corners (4 flips) and edges (6 flips) are omitted

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

Submission status: Accepted

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

if n==1 and m==1:
    print(1)
    sys.exit()
elif n==1:
    print(m-2)
    sys.exit()
elif m==1:
    print(n-2)
    sys.exit()
else:
    print((n-2)*(m-2))

Submission status: Accepted

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

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

if N == 1:
    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())

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a,b=map(int,input().split());print(abs((a-2)*(b-2)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

iN,iM = map(int,input().split())

if 2 < iN and 2 < iM:
    print((iN-2)*(iM-2))
elif iN == 2 or iM == 2:
    print(0)
else:
    if iN > 1:
        print(iN-2)
    elif iM > 1:
        print(iM-2)
    else:
        print(1)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# nがmより大きければ交換 (n <= mにする)
if n > m:
    n, m = m, n

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if n > m:
    k = n
    n = m
    m = k

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

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

elif n == 2:
    print(0)

Submission status: Accepted

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

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

men = N*M

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input().split()
l=[int(i) for i in s]
l.sort()
if l[0]==1:
  print(abs(l[1]-2))
else:
  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)
elif n ==1 or m == 1:
    print(n*m-2)
else:
    print((n-2)*(m-2))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = [int(v) for v 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:
    ans = (n-2) * (m-2)

print(ans)

Submission status: Accepted

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

if n>2:
    n-=2
if m>2:
    m-=2
if n==2 or m==2:
    print(0)
else:
    print(n*m)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
Keys=list(map(int,input().split()))
if Keys[0]>=2 and Keys[1]>=2:
    print(Keys[0]*Keys[1]-2*(Keys[0]+Keys[1]-2))
elif Keys[0]==1 and Keys[1]==1 :
    print(1)
else:
    print(max(Keys[0],Keys[1])-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)
	else:
		print(max(N, M)-2)
else:
	print((N-2)*(M-2))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

A = list(map(int, input().split()))

N = min(A)
M = max(A)

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

if(N > 2 and M > 2):
    print((N - 2) * (M - 2))
else:
    if(N == 2 or M <= 2):
        print(0)
    else:
        print(M-2)