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

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

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
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 == 1 and M == 1:
    ans = 1
elif N == 1:
    ans = M - 2
elif M == 1:
    ans = N - 2
else:
    ans = N*M - 2*(N+M-2)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N,M = inpl()

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

Submission status: Accepted

Solution code:
#encoding utf-8

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

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

print(reverse)

Submission status: Accepted

Solution code:
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


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

Submission status: Accepted

Solution code:
ary = list(map(int, input().split()))
ary = sorted(ary)

ans = -1
if ary[0] == 1:
    ans = 1 if ary[1] == 1 else (ary[1] - 2)
elif ary[0] == 2:
    ans = 0
else:
    ans = (ary[0] - 2) * (ary[1] - 2)
print(ans)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Aug  8 21:52:29 2018

@author: Yuki
"""

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

Submission status: Accepted

Solution code:
data = [int(n) for n in input().split()]

if(data[0] == 1 and data[1] == 1):
    print(1)
elif(min(data)==1):
    print(max(data)-2)
else:
    print((data[0]-2)*(data[1]-2))

Submission status: Accepted

Solution code:
import numpy as np

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

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

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

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

Submission status: Accepted

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

n_ = 1 if n == 1 else n-2
m_ = 1 if m == 1 else m-2
print(n_*m_)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b = map(int,input().split())
c = [a,b]
c.sort()
if c[0] == 1:
    if c[1]==1:
        print(1)
    else:
        print(c[1]-2)
else:
    print((c[0]-2) * (c[1]-2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ans = -1
inp = sorted([n, m])
if inp[0] == 1:
    if inp[1] == 1:
        ans = 1
    else:
        ans = inp[1] - 2
else:
    ans = (inp[0] - 2) * (inp[1] - 2)
print(ans)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if N==1 and M==1:
    print(1)
elif N==1 and 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:
#-*-coding:utf-8-*-

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

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

if __name__ == '__main__':
    main()

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

Submission status: Accepted

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


i = max((N - 2), 0) * max((M - 2), 0)
s = max((M - 2), 0) if N == 1 else 0
v = max((N - 2), 0) if M == 1 else 0
c = 1 if N == 1 and M == 1 else 0


print(i+s+c+v)

Submission status: Accepted

Solution code:
# your code goes her
n,m = map(int,input().split())

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

a = min(n, m)
b = max(n, m)

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

Submission status: Accepted

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

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:

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

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

Submission status: Accepted

Solution code:
a=list(map(int,input().split(' ')))
M=max(a[0],a[1])
N=min(a[0],a[1])

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def line_input(f, type):
    return f(map(type, input().split(" ")))

n, m = line_input(tuple, int)

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:
# coding: utf-8
# Your code here!
A,B=map(int,input().split())

if A==1 and B==1:
    print(1)

elif A ==1 or B==1:
    print(A*B-2)

else:
    print(A*B-2*A-2*B+4)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def main():
    nm = [int(i) for i in input().split()]

    nm.sort()
    # 自身と周辺のカードの枚数を数えて、偶数なら表、奇数なら裏
    if nm[0] == 1 and nm[1] == 1:
        # 1枚の時
        print(1)
    elif nm[0] == 1 and nm[1] == 2:
        # 2枚の時
        print(2)
    elif nm[0] == 1 and nm[1] > 2:
        # 1列の時、両端は自身と隣接2枚、途中は3枚なので、途中が裏
        print(nm[1] - 2)
    elif nm[0] == 2:
        # 2列の時、4隅が自身と隣接4枚、他は6枚
        print(0)
    elif nm[0] > 2 and nm[1] > 2:
        # 3行3列以上の時、4隅が4枚、端は6枚、真ん中は9枚
        print((nm[0]-2) * (nm[1]-2))
    else:
        raise ValueError


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

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

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,raw_input().split())

if n == 1 or m == 1:
	print abs(n*m-2)

elif n==2 or m==2:
	print 0

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:
  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:
m , n = map(int,input().split(" "))


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 13 17:57:26 2018


N*Mで裏返しのカード
あるマスとその8近傍のカードを裏返す
全てのマスに同様の処理を行う
表のカードの枚数を出力する


入力
1 7

出力
5


@author: Yuya
"""

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

if N > 1 and M > 1:
    print((N-2)*(M-2))
else:
    ans1 = N-2
    ans2 = M-2
    ans = abs(ans1*ans2)
    print(ans)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:

line=input()
line=line.rstrip().split(" ")
N1=int(line[0])
N2=int(line[1])
print(abs(N1*N2-((N1-2)*2+(N2-2)*2)-4))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(Ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(m())

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    n = N - 1
    m = M - 1
    if not n and not m:
        ans = 1
    elif not n or not m:
        ans = n + m -1
    else:
        ans = (n - 1) * (m - 1)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

# 入力を各変数に格納
n, m = map(int, input().split())

ans = 0

# 行列ともに1
if n == 1 and m == 1:
    ans = 1
# 行が1
elif n == 1:
    ans = m - 2
# 列が1
elif m == 1:
    ans = n - 2
# 行列とも1ではない
else:
    ans = (n - 2) * (m - 2)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if N == 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:
    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, raw_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 c_flip(N, M):
    if N == 1 and M == 1:
        ans = 1  # 1枚のカードが1回裏返される
    elif min(N, M) == 1:  # カードは1列に並んでいる
        # 両端のカードは2回、その他のカードは3回裏返される
        ans = max(N, M) - 2
    else:
        # 四隅は4回、その他の周上は6回、それ以外は9回裏返される
        ans = (N - 2) * (M - 2)
    return ans

N,M = [int(i) for i in input().split()]
print(c_flip(N, M))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if N>M:
    tmp=N
    N=M
    M=tmp

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

Submission status: Accepted

Solution code:
n, m = input().split()
n = int(n)
m = int(m)
ans = 0
if min(m, n) != 1:
    ans = max(n * m - (2 * n + 2 * m - 4), 0)
else:
    ans = max(max(n, m) - 2, 1)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# C
n, m = sorted([int(s) for s in input().split()])
if n == m == 1:
    sol = 1
elif n == 1:
    sol = m - 2
elif n == 2:
    sol = 0
else:
    sol = (n - 2) * (m - 2)
print(sol)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    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*M - (N*2 + M*2 - 4 ))
    
if __name__=="__main__":
    main()

Submission status: Accepted

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

if n>1 and m>1:
    print((n-2)*(m-2))
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 = list(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:
num = 0
nm1 = [int(x) for x in input().split()]

if nm1[0] == 1 and nm1[1] == 1:
    print(nm1[0])
elif nm1[0] == 1:
    print(nm1[1]-2)
elif nm1[1] == 1:
    print(nm1[0]-2)
else:
    print((nm1[0]-2)*(nm1[1]-2))

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    N, M = [int(x) for x in stdin.readline().rstrip().split()]
    # mtx = [[True for x in range(M)] for y in range(N)]
    # for x in range(M):
    #     for y in range(N):
    #         ps = [(x - 1, y - 1), (x, y - 1), (x + 1, y - 1),
    #               (x - 1, y), (x, y), (x + 1, y),
    #               (x - 1, y + 1), (x, y + 1), (x + 1, y + 1)]
    #         for px, py in ps:
    #             if px < 0 or py < 0 or M - 1 < px or N - 1 < py:
    #                 continue
    #             mtx[py][px] = not mtx[py][px]
    # for m in mtx:
    #     print(m)

    MIN = min(N, M)
    MAX = max(N, M)
    if MIN == 1 and MAX == 1:
        result = 1
    elif MIN == 1:
        result = MAX - 2
    elif MIN == 2:
        result = 0
    else:
        result = (MIN - 2) * (MAX - 2)
    print(result)


if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#1. input
# set N<=M 
N, M = map(int, input().split())

if N>M:
    temp = N
    N = M
    M = temp

#2. N=1 -> M-2 (if M=1, ans=1)
#    N=2 -> ans = 0
#    N>3 -> ans = NM - {2(M+N)-4}
if N == 1:
    if M == 1:
        ans = 1
    else:
        ans = M-2
elif N == 2:
    ans = 0
else:
    ans = M*N - 2*(M+N) +4
    
print(ans)

Submission status: Accepted

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

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

elif n == 1 or m == 1:
    print(n*m-2)

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

Submission status: Accepted

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

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 == 1 and M == 1:
    print(1)

Submission status: Accepted

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

if (n == 1) & (m == 1):
    print(1)
elif (n == 1) | (m == 1):
    print(max([n, m]) - 2)
elif (n == 2) | (m == 2):
    print(0)
else:
    print((n - 2) * (m - 2))

Submission status: Accepted

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

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

Submission status: Accepted

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

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 = input().split()

n = int(n)
m = int(m)

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