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:
import sys
if sys.platform in ['ios', 'win32', 'darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(x) for x in input().split()]

H, W = MAP()
# M = [[0]*W for _ in range(H)]
# # print(M)

# MOVE = [-1,-1],[-1,0],[-1,1],[0,-1],[0,0],[0,1],[1,-1],[1,0],[1,1]

# for h in range(H):
# 	for w in range(W):
# 		for dh, dw in MOVE:
# 			nh = h + dh
# 			nw = w + dw
# 			if nh<0 or nh>H-1 or nw<0 or nw>W-1:
# 				continue
# 			#print(nh, nw)
# 			M[nh][nw] += 1

# ans = 0
# for m in M:
# 	for mm in m:
# 		if mm%2: ans+=1
# print(ans)

if H==1 and W==1:
	print(1)
else:
	cards = H*W
	if min(H,W) >= 2:
		edges = (H+W)*2-4
	else:
		edges = 2

	edges = (H+W)*2-4 if min(H,W) >= 2 else 0 if H==0 and W== 0 else 2 if min(H,W) == 1 else 0
	#print(cards, edges)
	print(cards-edges)

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

Submission status: Accepted

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

Submission status: Accepted

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

tate = N - 2 if N >= 3 else 0 if N == 2 else 1
yoko = M - 2 if M >= 3 else 0 if M == 2 else 1

print(tate * yoko)

Submission status: Accepted

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

#角、辺、内部の3つ分けて考える
#角は4flip -> 表
#辺は6flip -> 表
#内部は9flip -> 裏

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
print(((abs(max(N,M)-2)),(M-2)*(N-2))[min(N,M)>1])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if x >= 2 and y >= 2:
    print((x-2)*(y-2))
elif x >=2 or y >= 2:
    print(x*y - 2)
else:
    print(1)

Submission status: Accepted

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

N,M = inpl()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if M==1:
    if N==1:
        #1回フリップ
        print(1)
    elif N==2:
        #全て2回フリップ
        print(0)
    elif N>2:
        #両端は2回フリップ、それ以外は3回フリップ
        print(M*N - 2)
elif M==2:
    if N==1:
        #全て2回フリップ
        print(0)
    elif N==2:
        #全て4回フリップ
        print(0)
    elif N>2:
        #両端4枚は4回フリップ、それ以外は6回フリップ
        print(0)
elif M>2:
    if N==1:
        #両端は2回フリップ、それ以外は3回フリップ
        print(M*N - 2)
    elif N==2:
        #両端4枚は4回フリップ、それ以外は6回フリップ
        print(0)
    elif N>2:
        #角は4回フリップ
        #角以外の周辺は6回フリップ
        #それ以外は9回フリップ
        print((M-2)*(N-2))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

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

Submission status: Accepted

Solution code:
def examC():
    NM = LI(); NM.sort()
    if NM[0]>=2:
        ans = (NM[0]-2)*(NM[1]-2)
    else:
        if NM[1]==1:
            ans = 1
        else:
            ans = max(0,NM[1]-2)
    print(ans)


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Submission status: Accepted

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

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

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

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

if M == 1:
    if N >= 3:
        print(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(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:
    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 >= 2 and m == 1:
    print(n-2)
elif n == 1 and m >= 2:
    print(m-2)
elif n >= 2 and m >= 2:
    # 4隅が表、4隅以外の外周が表、それ以外が裏
    # つまり外周を取り除いたところが裏
    print((n-2)*(m-2))

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
import math

n,m = [int(x) for x in stdin.readline().rstrip().split()]

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = list(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:
N, M = map(int, input().split())
if N == 1 and M == 1:
    print(1)
elif (N == 1 and M >= 2) or (M == 1 and N >= 2):
    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 max(N, M) == 1:
    ans = 1
  else:
    ans = max(N, M) - 2
elif (N == 2) or (M == 2):
  ans = 0
else:#N, M共に3以上
  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(n*m-2*m-2*n+4)
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 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 = 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())
# c = [[0]*n for _ in range(m)]

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

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, readline().split()))
    if n == 1 and m == 1:
        print(1)
    elif n == 1 or m == 1:
        print(n * m - 2)
    elif n == 2 or m == 2:
        print(0)
    else:
        print(n * m - 2 * n - 2 * m + 4)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N, M = [int(x) for x in input().split()]
if N == M == 1:
  print(1)
elif N == 1 or M == 1:
  print(max(0, N - 2) + max(0, M - 2))
else:
  print((N - 2) * (M - 2))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1

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

main()

Submission status: Accepted

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-06 21:30:22(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator

def main():
    n, m = (int(x) for x in sys.stdin.read().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)

if __name__ == "__main__":
    # execute only if run as a script
    main()

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
a,b = map(int,s.split(' '))
if a==1 and b == 1:
    print(1)
else:
    if 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 and m!=1:
  print(m-2)
elif n!=1 and m==1:
  print(n-2)
else:
  print(n*m-2*n-2*m+4)

Submission status: Accepted

Solution code:

if __name__ == '__main__':

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

zenbu = N*M
naka = max(N-2,0)*max(M-2,0)
kado = [4,2,1][[N,M].count(1)]
hen = N*M-naka-kado

if N==M==1:
    print(1)
elif N==1 or M==1:
    print(hen)
else:
    print(naka)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 全操作終了後に裏になるカードは、以下のような配置にあるカードのみ
# 1. 上下左右斜めを他のカードに囲まれているカード
# 2. 上下 or 左右 のみ他のカードに囲まれているカード
# 1が成り立つのは、行・列数ともに3以上の場合で、2が成り立つのは行・列数のどちらかが1で、もう一方が3以上の場合
# それぞれ、裏になっているカードの数は
# 1. → (M-2) * (N-2)
# 2. → 1 * (N-2) （N>=3 の場合）

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

m = M - 2
if m < 0:
    m = 1
n = N - 2
if n < 0:
    n = 1

print(m * n)

Submission status: Accepted

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

Submission status: Accepted

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

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:
n,m=map(int,input().split())
ans=0
if n==m==1:
  ans=1
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:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

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



if __name__ == '__main__':
    main()

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 and m == 2:
    print(0)
    sys.exit()
if n == 2 and m == 1:
    print(0)
    sys.exit()
if n == 1:
    print(m - 2)
    sys.exit()
if m == 1:
    print(n - 2)
    sys.exit()
if n == 2 and m == 2:
    print(0)
    sys.exit()
if n == 2 or m == 2:
    print(0)
    sys.exit()

center = (n - 2) * (m - 2)

print(center)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == "__main__":
    test()

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
        ans = 1
    else:
        ans = M - 2

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
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())

# カードがあるマスと周囲を合わせた9マスに存在するカードの数だけ裏返る
# 裏返る回数が奇数回数になるのは、端以外の全てのカード

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
ls=[int(s) for s in input().split()]
ls.sort()
if ls[1]==1:
  print(1)
elif ls[0]==1:
  print(ls[1]-2)
else:
  print((ls[0]-2)*(ls[1]-2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import sys
input = sys.stdin.readline
def inputs():return [int(x) for x in input().split()]
N,M = inputs()
if N>=2 and M>=2:
    print((N-2)*(M-2))
    exit()
else:
    if N==1 and M==1:
        print(1)
        exit()
    print(max(N-2,M-2))

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

Submission status: Accepted

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

if m >= 2:
  n9 = (n-2) * (m-2)
  n4 = 4
  n6 = n * m - n9 - n4
  print(n9)
elif m == 1 and n >= 2:
  n2 = 2
  n3 = n * m - 2
  print(n3)
elif m == 1 and n == 1:
  print(1)

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, M] = string_to_int(inputs[0])
    if N == 1 and M == 1:
        return 1
    if N == 1 or M == 1:
        return (N * M) - 2
    # if N == 2 and M == 2:
    #     return 0
    if N == 2 or M == 2:
        return 0

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


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    print(abs(n-2)*abs(m-2))
resolve()

Submission status: Accepted

Solution code:
import sys

N, M = map(int, input().split())
if N < 2 and M < 2:
    print(1)
    sys.exit()

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

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

Submission status: Accepted

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

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

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
"""

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

Submission status: Accepted

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

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:
a=sorted(list(map(int,input().split())))
n=a[0]
m=a[1]
if n*m==1:
  print(1)
elif n==1:
  print(m-2)
else:
  print((n-2)*(m-2))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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