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:
# -*- coding: utf-8 -*-


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def calc(n, m):
    if n == 1:
        if m == 1:
            return 1
        if m == 2:
            return 0
        if m >= 3:
            return m - 2
    elif n == 2:
        return 0
    else:
        if m == 1:
            return n - 2
        elif m == 2:
            return 0
        else:
            return (n - 2) * (m - 2)


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(r)

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

Submission status: Accepted

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

Submission status: Accepted

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

if N == 1:
    n = N
else:
    n = N - 2
if M == 1:
    m = M
else:
    m = M -2

print(n * m)

Submission status: Accepted

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

Submission status: Accepted

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

x = n - 2
if x < 0:
    x = 0

y = m - 2
if y < 0:
    y = 0

if n == 1 and m == 1:
    print(1)
elif n == 1 and m > 1:
    print(y)
elif n > 1 and m == 1:
    print(x)
else:
    print(x * y)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if N >= 2:
	N -= 2

if M >= 2:
	M -= 2

print(N * M)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

a=input().rstrip().split(" ")
n=int(a[0])
m=int(a[1])
sum=0
if(n==1 and m==1):
    print(1)
elif(n==2 or m==2):
    print(0)
elif(n==1 or m==1):
    print(n*m-2)
else:
    print((n-2)*(m-2))

Submission status: Accepted

Solution code:
S = input().split(" ")
A = int(S[0]) * int(S[1]) - int(S[0])*2 - (int(S[1])*2-4)
if (int(S[0]) == 1 or int(S[1]) == 1) and int(S[0]) * int(S[1]) != 1:
    A = int(S[0]) * int(S[1]) - 2
A = max(0,A)
print(A)

Submission status: Accepted

Solution code:
N, M = [int(x) for x in input().split()]
n = N - 2 if N > 1 else 1
m = M - 2 if M > 1 else 1
print(n * m)

Submission status: Accepted

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

Submission status: Accepted

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

C = abs((N - 2) * (M - 2))

print(C)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if max(n, m) == 1:  # One point
    print 1
elif min(n, m) == 1:  # A line
    print max(n, m) - 2
    # End nodes have 1 neighbor each
    # Non-end nodes have 2 neighbors
else:
    print (n - 2) * (m - 2)  # Internal points have 8 neighbors
    # All corner points have 3 neighbors
    # All non-corner border nodes have 5 neighbors

Submission status: Accepted

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


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:
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:
import numpy as np

n, m = list(map(int, input().split()))
a = 0

if n == 1 or m == 1:
    if n == m:
        a = 1
    else:
        a = n + m - 3
elif n == 2 or m == 2:
    a = 0
else:
    a = (n - 2) * (m - 2)

print(a)

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:
x,y = (int(i) for i in input().split())
if x == 2 or y == 2: answer = 0
elif x == 1 and y == 1: answer = 1
elif x == 1 or y == 1: answer = x+y-3
else: answer = (x-2)*(y-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 == 2 or M == 2:
    print(0)

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:
data = input()
data = data.split(" ")
n = int(data[0])
m = int(data[1])
if n>1 and m>1: print(n*m-2*(n+m)+4)
elif n==1 and m==1: print(1)
else: print(n*m-2)

Submission status: Accepted

Solution code:
#abc090c

n,m=map(int,raw_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())

if n > m:
    n, m = m, n

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

Submission status: Accepted

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

a = n - 2 if n > 2 else 0
b = m - 2 if m > 2 else 0
counter =  a * b

if counter == 0:
    if n == 1 and m == 1:
        counter = 1
    elif n == 1:
        counter = m - 2
    else:
        counter = n - 2

print(counter)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# スペース区切りの整数の入力
X,Y = map(int, input().split())

count=0
if X > 2 and Y > 2:
  count = (X-2) * (Y-2)
elif X == 1 and Y > 2:
  count = Y-2
elif Y == 1 and X > 2:
  count = X-2
elif X == 1 and Y == 1:
  count = 1

print( count )

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:
list = input().split(" ")
x = [int(y) for y in list]
if x[0] == 1 and x[1] == 1:
    count =1
elif x[0] == 1 or x[1] == 1:
    count = max(x[0], x[1])-2
else:
    count = (x[0]-2)*(x[1]-2)
print(count)

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-2)) * max(0,(M-2)))

Submission status: Accepted

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

X=0
if N==1:
    if M==1:
        X=1
    if M==2:
        X=0
    if M>=3:
        X=M-2
if N==2:
    X=0
if N>=3:
    if M==1:
        X=N-2
    if M==2:
        X=0
    if M>=3:
        X=(N-2)*(M-2)
        
print(X)

Submission status: Accepted

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

L=max(n,m)
S=min(n,m)

if L==1 and S==1:
    print(1)
elif S==1:
    print(L-2)
else: print((L-2)*(S-2))

Submission status: Accepted

Solution code:
n = raw_input()
n= n.split()
N = int(n[0])
M = int(n[1])
if N ==1 and M == 1:
	ANS = 1
if (N == 1 and M  >= 2) or (M == 1 and N >= 2) :
	ANS = N*M - 2
elif N >= 2 and M >= 2:
	ANS = (N-2)*(M-2)
	
print(ANS)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
if n == 1 and m == 1:
    ans = 1
elif n == 1:
    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:
j = list(map(int, input().split()))
counter = 0
j.sort()

if (j[0] >= 3):
  print((j[0] - 2) * (j[1] - 2))
elif (j[0] == 2):
  print(0)
elif (j[0] == 1):
  if j[1] == 1:
    print(1)
  else:
    print(j[1] - 2)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
print(abs(eval('~-~-'+input().replace(' ','*~-~-'))))

Submission status: Accepted

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

solve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, m = sorted([int(i) for i in input().split()])
a = None
if n == 1 and m == 1:
    a = 1
elif n == 1:
    a = m - 2
else:
    a = (n - 2) * (m - 2)
print(a)

Submission status: Accepted

Solution code:
eval('print(abs(('+input().replace(' ','-2)*(')+'-2)))')

Submission status: Accepted

Solution code:
print(eval('abs(('+input().replace(' ','-2)*(')+'-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:
a = list(map(int, input().split()))
if a[0] == 1 and a[1] == 1:
    b = 1
elif a[0] == 1:
    b = a[1] - 2
elif a[1] == 1:
    b = a[0] - 2
else:
    b = (a[0] - 2) * (a[1] - 2)
print(b)

Submission status: Accepted

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

Submission status: Accepted

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

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(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())
ans = 0

def retCard(n,m):
    global ans
    # 特殊パターン対応
    if n == 1 and m == 1:
        ans = 1
        return 0
    if n == 2 and m == 2:
        ans = 0
        return 0
    if n == 1 or m == 1:
        ans = max(n,m) - 2
        return 0
    # 通常パターン
    ans = (n - 2) * (m - 2)
    return 0

retCard(N,M)
print(ans)

Submission status: Accepted

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

if (N == 1) & (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:
# -*- coding: utf-8 -*-
"""
C - Flip,Flip, and Flip......
https://beta.atcoder.jp/contests/abc090/tasks/arc091_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(N, M):
    if N == 1:
        if M == 1:
            return 1
        else:
            return M - 2
    if M == 1:
        return N - 2

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



def main(args):
    N, M = map(int, input().split())
    ans = solve(N, M)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
lis = list(map(int, input().split()))
n = lis[0]
m = lis[1]
count = 0

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

Submission status: Accepted

Solution code:
def c_flip(N, M):
    if N == 1 and M == 1:
        # 1枚のカードが1回裏返される
        return 1
    elif N == 1 or M == 1:
        # 1列の両端のカードは2回、その他のカードは3回裏返される
        return max(N, M) - 2
    else:
        # 四隅は4回、その他の周上は6回、それ以外は9回裏返される
        return (N - 2) * (M - 2)
    return None 

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

Submission status: Accepted

Solution code:
input_data = input().split()
n = int(input_data[0])
m = int(input_data[1])

if n == 1 or m == 1:
    if 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)

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

Submission status: Accepted

Solution code:
n,m = [int(i) for i in input().split()]
if n > 1 and m > 1:
    print(n*m-(n+m)*2 + 4)
else:
    if n == m == 1:
        print("1")
    else:
        print(n*m-2)

Submission status: Accepted

Solution code:
rows, columns = map(int, input().split(' '))

if rows == 1 and columns == 1:
    print(1)
    exit()

if rows == 1:
    print(columns - 2)
    exit()

if columns == 1:
    print(rows - 2)
    exit()

print(rows * columns - 2 * rows - 2 * columns + 4)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
n,m=map(int,input().split())
if n==m==1:
    print(1)
    exit()
ans=0
ans+=max((n-2),0)*max((m-2),0)
if n==1 and n!=m or m==1 and m!=n:
    ans+=max(n,m)-2
print(ans)

Submission status: Accepted

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

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

elif N == 2 or M == 2:
    print(0)
    
else:
    print(N*M - ((N-2)*2+(M-2)*2+4))

Submission status: Accepted

Solution code:
n,m = map(int, raw_input().split(" "))
if n==1==m:
    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:
N,M=input().split()
N,M=[int(N),int(M)]

def countCard(j,i):
	count = 0
	left=0
	right=0
	up =0
	down=0

	if j-1 >= 0:
		left = 1

	if j+1 < M:
		right = 1

	if i-1 >= 0:
		up = 1

	if i+1 < N:
		down = 1

	a= left + right + up + down
	if a == 4:
		return 0	#9
	elif a == 3:
		return 1	#6
	elif a == 2:
		if left + right == 0 or up+down==0:
			return 0	#3
		else:
			return 1	#4
	elif a == 1:
		return 1	#2
	elif a == 0:
		return 0

ans = 0

if M >= 3 and N >=3:
	ans = (M-2)*(N-2)
elif M == 1 and N ==1:
	ans = 1
elif N == 1 and M > 2:
	ans = M -2
elif M ==1 and N>2:
	ans = N-2
else:
	status = [[1]*M]*N
	for i in range(N):
		for j in range(M):
			status[i][j] = countCard(j,i)
			ans += status[i][j]
	ans = (M*N) - ans

print(ans)

Submission status: Accepted

Solution code:
#coding=utf-8

def check_circle(s):
    x = str(s)
    flag = True
    for i in range(int(len(x) / 2)):
         if x[i] != x[-1 * (i + 1)]:
              flag = False
    return flag

def solve(N, M):
    return abs((N - 2) * (M - 2))
    if N == 1:
        return N * M - 2
    if M == 1:
        return N * M - 2
    return N * M - 4
    if N == M and N == 1:
        return 1
    if N == M and N == 0:
        return 0

    if N >= 2:
        tate = 2 * (M - 2)
    elif N == 1:
        tate = M - 2
    if M >= 2:
        yoko = 2 * (N - 2)
    elif M == 1:
        yoko == M - 2
    else:
        yoko = N - 2
    ans = tate + yoko
    return ans

def main():
    N, M = input().split(' ')
    print(solve(int(N), int(M)))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

n,m = input().split()

N = int(n)
M = int(m)

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

Submission status: Accepted

Solution code:
l = raw_input().split()
a = int(l[0])
b = int(l[1])
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:
# coding:utf-8

in1 = input().split()

in1 = [int(i) for i in in1]

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

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    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:
L,M=map(int,input().split())
count=0
if L==1 and M==1:
    print(1)
elif L==1 or M==1:
    print(L+M-3)
if L==2 or M==2:
    print(0)
if L>=3 and M>=3:
    print((L-2)*(M-2))

Submission status: Accepted

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

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

Submission status: Accepted

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

if n >= 2 and m >= 2:
    print((n - 2) * (m - 2))
elif n == 1 and m == 1:
    print(1)
else:
    print(n * 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:
im = []
im = input().split(' ')
N = int(im[0])
M = int(im[1])
if (N == 1 and M == 1) or (N != 1 and M != 1):
    print((N - 2) * (M - 2))
else:
    print(N * M - 2)

Submission status: Accepted

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

    f(N, M)


def f(N, M):
    """
    カードAおよび周り8方向を裏返す
    すべてのカードについて行う
    うらの数(1)の枚数

    1 <= N,M <= 10^9
        シミュレート: TLE
    """
    ans = 0
    if N == 1 and M == 1:
        ans = 1
    elif N == 2 or M == 2:
        ans = 0
    elif N >= 3 and M >= 3:
        ans = (N-2) * (M-2)
    else:
        # 3>,1 or 1,3>
        ans = max(N, M) - 2

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
N = a[0]
M = a[1]
sum = N*M
delt = N*2+(M-2)*2
sum = abs(sum -delt)
print(sum)

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
def judge(x):
    if x == 1:
      return 1
    elif x == 2 or x == 3:
	    return 0
    elif x > 4:
      return x-2
      
a = judge(a)
b = judge(b)

print(a*b)

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N, M = list(map(int, (input().split(' '))))
    ura = 0
    if N == 1 and M != 1:
        arr = [0 for i in range(N)]
        ura = M - 2
    elif N != 1 and M == 1:
        arr = [0 for i in range(M)]
        ura = N - 2
    elif N == 1 and M == 1:
        ura = 1
    else:
#        arr = [[0 for i in range(M)] for j in range(N)]
#        for i in range(N):
#            for j in range(M):
#                for buf_i in range(-1, 2):
#                    for buf_j in range(-1, 2):
#                        if i-buf_i < 0 or i+buf_i >= N or j-buf_j < 0 or j+buf_j >= M:
#                            continue
#                        if arr[i+buf_i][j+buf_j] == 0:
#                            arr[i+buf_i][j+buf_j] = 1
#                        else:
#                            arr[i+buf_i][j+buf_j] = 0
#        for i in range(N):
#            for j in range(M):
#                if arr[i][j] == 1:
#                    ura += 1
        ura = N * M - (N * 2 + M * 2 - 4)
    print(ura)

Submission status: Accepted

Solution code:
A,B=map(int,input().split(' '))
A=1 if A==1 else A-2
B=1 if B==1 else B-2
print(A*B)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

p = n - 2
if p < 0:
    p = 1
q = m - 2
if q < 0:
    q = 1
res = p * q

print(res)

Submission status: Accepted

Solution code:
#coding:utf-8

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


a = n-2 if n>1 else 1
b = m-2 if m>1 else 1

print(a*b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import sys

N,M = map(int, input().split(' '))
num = 0
if N == 1:
    if M < 2:
        print(1)
        sys.exit()
    print(str(M-2))
    sys.exit()
elif N == 2:
    print(0)
    sys.exit()
else:
    if M < 2:
        num = N-2
    else:
        num = (M-2)*(N-2) 
    print(num)

Submission status: Accepted

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

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

if n==1:
    ans=m-2
if m==1:
    ans=n-2

if n==1 and m==1:
    ans=1
if n==2 and m==1:
    ans=0
if m==2:
    ans=0


print(ans)

Submission status: Accepted

Solution code:
IN = input().split(" ")
N = int(IN[0])
M = int(IN[1])
if M == 1 and N != 1:
    print(N - 2)
elif N == 1 and M != 1:
    print(M - 2)
else:
    print(M*N-2*N-2*M+4)

Submission status: Accepted

Solution code:
A,B = map(int,input().split(" "))
ans = 0
if A >=3 and B >= 3:
    ans = A*B-(A*2 + B*2)+4
    print(ans)

if A == 1 and B!=1:
    print(B-2)
elif B == 1 and A != 1:
    print(A-2)
elif A == 1 and B ==1:
    print(1)
elif A == 2 and B >=2:
    print(0)
elif B == 2 and A >=2:
    print(0)

Submission status: Accepted

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

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

Submission status: Accepted

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

    if min(N, M) == 1:
        i = max(N, M)
        if i == 1:
            back = 1
        elif i == 2:
            back = 0
        else:
            back = i - 2
    elif N == 2 or M == 2:
        back = 0
    else:
        back = N * M - ((N + M) * 2 - 4)
    print(back)

main()

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N, M = [int(v) for v in input().split()]

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

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

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

Submission status: Accepted

Solution code:
#coding:utf-8
n, m = list(map(int, input().split()))
count = 0
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:
a = input()
a = a.split(' ')
A = eval(a[0])
B = eval(a[1])
if A == 2 or B == 2:
    print('0')
else:
    print(abs(A - 2) * abs(B - 2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
  c = list(map(int, input().split(' ')))
  if c[0] >= 3 and c[1] >= 3:
    return (c[0] - 2) * (c[1] - 2)
  if c[0] == 1 or c[1] == 1:
    if c[0] == 1 and c[1] == 1:
      return 1
    else:
      return max(max(c) - 2, 0)
  return 0

print(solve())

Submission status: Accepted

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

if n > m: n,m=m,n

ans=0
if n==1:
	if m==1: ans = 1
	if m==2: ans = 0
	if m>=3: ans = m-2

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n,m = na()

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

Submission status: Accepted

Solution code:
f = lambda :[int(i) for i in input().split()]

N,M = f()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if __name__ == "__main__":
    N, M = list(map(int, input().split()))
    # 各マスにおいて、隣接するマス（自分含む）が奇数のマスが裏になる
    if N == 1 and M == 1:
        print("1")
    elif N <= 2 and M <= 2:
        print("0")
    elif N == 1 and M >= 3:
        print(M-2)
    elif N >= 3 and M == 1:
        print(N-2)
    else:
        print((N-2)*(M-2))

Submission status: Accepted

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

Submission status: Accepted

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