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

Submission status: Accepted

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

ans = 0
if N == 1 and M == 1:
    ans = 1
elif N == 1:
    ans = M - 2
elif 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:
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*m-2*n+4)

Submission status: Accepted

Solution code:
# 2019/07/23

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 書けばわかる 裏になるのは奇数回訪れる場所
n, w = map(int, input().split())
print(abs(n*w-(2*n+2*w-4)))

Submission status: Accepted

Solution code:
# ABC090C - Flip, Flip, and Flip...... (ARC091C)
def main():
    n, m = sorted(list(map(int, input().rstrip().split())))
    print(abs((n - 2) * (m - 2)))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ARC091C - Flip, Flip, and Flip...... (ABC090C)
def main():
    n, m = sorted(list(map(int, input().rstrip().split())))
    if (n, m) == (1, 1):
        print(1)
    elif n == 1:
        print(m - 2)
    elif n == 2:
        print(0)
    else:
        print((n - 2) * (m - 2))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

n, m = sorted([ int(v) for v in input().split() ])
if n == 1:
	if m == 1:
		ans = 1
	else:
		ans = m - 2
else:
	ans = (n-2)*(m-2)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# 上端
edge_l=1
if m > 1:
    edge_l+=1
if n > 1:
    edge_l+=1
if m > 1 and n > 1:
    edge_l+=1

edge_l = 1 if edge_l%2==1 else 0

edge_c=3
if n > 1:
    edge_c+=3
edge_c = 1 if edge_c%2==1 else 0

edge_row=edge_l
if m>1:
    edge_row+=edge_l
if m>2:
    edge_row+=(m-2)*edge_c

# 中央部
inner_l = 3
if m > 1:
    inner_l+=3
inner_l = 1 if inner_l%2==1 else 0

inner_c=1 # 絶対に裏

inner_row=inner_l
if m>1:
    inner_row+=inner_l
if m>2:
    inner_row+=(m-2)*inner_c

# 合計
total=edge_row
if n>1:
    total+=edge_row
if n>2:
    total+=(n-2)*inner_row
print(total)

Submission status: Accepted

Solution code:
import numpy as np

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

"""
stage = [[0 for _ in range(W)] for _ in range(H)]
ds = ((0, 0), (1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1))

def setv(p, v):
	global stage
	stage[p[1]][p[0]] = v

def getv(p):
	return stage[p[1]][p[0]]

def move(p, d):
	r = (p[0] + d[0], p[1] + d[1])
	if not (0 <= r[0] < W) or not (0 <= r[1] < H):
		return None
	return r

for h in range(H):
	for w in range(W):
		for d in ds:
			nextp = move((w, h), d)
			if not nextp:
				continue
			setv(nextp, (getv(nextp) + 1) % 2)
			#setv(nextp, (getv(nextp) + 1))

for h in range(H):
	print(*stage[h], sep="")
print()
"""

if 1 == H == W:
	print(1)
	exit()

if 1 == H and not 1 == W:
	print(W - 2)
	exit()

if 1 == W and not 1 == H:
	print(H - 2)
	exit()

print((H - 2) * (W - 2))

Submission status: Accepted

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

Submission status: Accepted

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

if n > m: 
	a = n
	n = m
	m = a

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

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

solve()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
from collections import deque

INF = float('inf')
MOD = 10 ** 9 + 7
dy, dx = (0, -1, 0, 1), (1, 0, -1, 0)

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)

#x = ip()                                     #入力整数1つ
#n,m= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
## a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#k = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(h)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
a.sort()
if max(a) == 1:
    print(1)
elif min(a)==1:
    if max(a)==2:
        print(0)
    else: print(a[1]-2)
elif min(a)==2:
    print(0)
else:
    print((a[0]-2)*(a[1]-2))

Submission status: Accepted

Solution code:
import sys
from sys import stdin
N, M = [int(_) for _ in stdin.readline().rstrip().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:
    print(M-N*2)
elif M == 1:
    print(N-M*2)
else:
    print(N*M-2*M-2*(N-2))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))


n, m = MI()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 2019/04/17
# AtCoder Beginner Contest 091 - C

#四隅: 4回ー表
#四辺(四隅除く): 6回ー表
#中: 9回ー裏
#ただし1行or1列のとき、裏

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, raw_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 - 1 + M - 1) * 2

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def inpl(): return [int(i) for i in input().split()]
N, M = inpl()
if M < N:
    N, M = M, N
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 = list(map(int, input().split()))
n, m = max(n, m), min(n, m)
if n == 1 and m == 1:
    print(1)
else:
    a = min(2, n)
    b = max(0, n-2)
    c = min(2, m)
    d = max(0, m-2)
    if m == 1:
        print(b)
    else:
        print(b*d)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
 
if N == 2 or M == 2:
    print(0)
    exit()

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

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

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

Submission status: Accepted

Solution code:
N, M = [int(x) for x in 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 = list(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 - 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(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 == 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 == 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())

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

print(ans)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
l = list(map(int, input().split()))
l.sort()

# N < M
N, M = l

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

Submission status: Accepted

Solution code:
N,M = list(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 + 4 - 2*(N+M))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
h, w = map(int, input().split())
if h == 1 and w == 1:
    answer = 1
elif h == 1:
    answer = w - 2
elif w == 1:
    answer = h - 2
else:
    answer = (h - 2) * (w - 2)
print(answer)

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

Submission status: Accepted

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

Submission status: Accepted

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

if b[0] == 1 and b[1] == 1:
	print(1)
elif b[0] == 1:
	print(b[1]-2)
elif b[1] == 1:
	print(b[0] -2)

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

Submission status: Accepted

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

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

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 M*N == 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, raw_input().strip().split())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N, M = map(int, input().split())
    if (N > M):
        N, M = M, N
    if (N == 1):
        print(max(1, M - 2))
        exit(0)
    result = (N - 2) * (M - 2)
    print(result)

Submission status: Accepted

Solution code:

from collections import deque
lines = input().split(' ')
m = int(lines[0])
n = int(lines[1])

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

Submission status: Accepted

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

if H > W:
    H, W = W, H

if H == 1 and W == 1:
    print 1
elif H == 1:
    print W - 2
else:
    print (H - 2) * (W - 2)

Submission status: Accepted

Solution code:
N, M = map(int, raw_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==2 or m == 2:
	print(0)
elif 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 == 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 M > N:
    tmp = M
    M = N
    N = tmp

if N == 1 and M == 1: print(1)
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) # 0
elif N == 1 or M == 1:
    print(N*M-2) # 両端のぞく
else:
    print((N-2)*(M-2))

Submission status: Accepted

Solution code:
import math, string, fractions, heapq, re, array, bisect, sys, random, time, copy
import itertools as it
import collections as cl
import functools as ft


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

n, m = LI()
result = {
    (1, 1): 1,
    (1, 2): 0, (2, 1): 0,
    (2, 2): 0
}

if (n, m) in result.keys():
    print(result[(n, m)])
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:
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

(N, M) = reads()

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

print(ans)

Submission status: Accepted

Solution code:
def calc_flips(n,m):
    flips = {}
    if n==1 and m==1:
        flips[1]=1
    elif n==1 or m==1:
        flips[2]=2
        b = n if n>m else m
        flips[3]=b-2
    elif n==2 and m==2:
        flips[4]=4
    elif n==2 or m==2:
        flips[4]=4
        b = n if n>m else m
        flips[6]=(b-2)*2
    else:
        flips[4]=4
        flips[6]=((n-2)*2)+((m-2)*2)
        flips[9]=(n-2)*(m-2)
    return flips

def calc_backs(flips):
    num_backs = 0
    for k,v in flips.items():
        if k % 2 == 1:
            num_backs += v
    return num_backs

n,m = map(int, input().split())
flips = calc_flips(n,m)
num_backs = calc_backs(flips)
print(num_backs)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
if n>=2 and m>=2:#中心部
	ans = (n-2)*(m-2)
else:
	ans = 0

if m==1:#外周
	ans += (n-2)
if n==1:
	ans += (m-2)
	
if n*m==3:
	print('2')
elif n*m==2:
	print('0')
elif n*m==1:
	print('1')
else:
	print(ans)

Submission status: Accepted

Solution code:
def solve(N, M):
    if N * M == 1:
        return 1
    elif min(N, M) == 1:
        return max(N, M) - 2
    else:
        return (N-2) * (M-2)

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

Submission status: Accepted

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

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

N, M = [int(_) for _ in input().split()]

print(calc(N, M))

Submission status: Accepted

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


def a(nm):
    if nm == 1:
        return 1
    else:
        return nm - 2


print(a(n) * a(m))

Submission status: Accepted

Solution code:
Tmp = []
Tmp = input().rstrip().split(' ')

N = int(Tmp[0])
M = int(Tmp[1])

Ans = 0

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

print(Ans)