Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

1 \leq N,M \leq 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

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

Sample Input 1

2 2

Sample Output 1

0

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

Sample Input 2

1 7

Sample Output 2

5

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

Sample Input 3

314 1592

Sample Output 3

496080



Sample input:
2 2


Sample output:
0

Submission status: Accepted

Solution code:
n, m = [int(i) for i in input().split()]
if n >= 3 and m >= 3:
    ans = (n - 2) * (m - 2)
elif n == 1 and m == 1:
    ans = 1
elif n == 1 and m >= 2:
    ans = m - 2
elif n >= 2 and m == 1:
    ans = n - 2
elif n == 2 or m == 2:
    ans = 0

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n,m = LI()
    if n > m:
        n,m = m,n
    ans = 0
    if n == 1:
        ans = abs(m-2)
    elif n == 2:
        ans = 0
    else:
        ans = (n-2)*(m-2)

    print(ans)
main()

Submission status: Accepted

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

if n>1:
    uraN=n-2
else:
    uraN=1
    
if m>1:
    uraM=m-2
else:
    uraM=1
    
print(uraN*uraM)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
if n==1 and m==1:
  # 1マスのみ
  print(1)
elif n==1 or m==1:
  # 両端:2
  # 中ます:3
  print(max(m-2,n-2))
else:
  # 両端:4
  # 片端:6
  # 中マス:9
  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 = [int(i) for i in input().split()]

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, M = LI()

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

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys

N, M = map(int, sys.stdin.readline().split())

if N == 1 and M == 1:
    print(1)
elif N == 1 or M == 1:
    two = 2
    three = N * M - two
    print(three)
else:
    four = 4
    six = (N - 2) * 2 + (M - 2) * 2
    nine = N * M - four - six
    print(nine)

Submission status: Accepted

Solution code:
def resolve():
    N, M = [int(i) for i in input().split()]
    if min(N, M) > 1:
        print((N - 2) * (M - 2))
    else:
        if max(N, M) == 1:
            print(1)
        else:
            print(max(N, M) - 2)


resolve()

Submission status: Accepted

Solution code:
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    n, m = map(int, readline().rstrip().split())
    print(abs((m - 2) * (n - 2)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    n, m = map(int, readline().rstrip().split())
    if n == 1 or m == 1:
        print(abs(abs(n - m) - 1))
        return
    print(abs((m - 2) * (n - 2)))


if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n,m=map(int,input().split())
    x = n*m
    if n == 1 and m == 1:
        x = 1
    elif n < 2 or m < 2: # 4隅
        x -= 2
    else:
        x -= (2*m + 2*n)-4
    print(max(0, x))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

if n > m:
    t = n
    n = m
    m = t

w = 0

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

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

Submission status: Accepted

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

def solve(n,m):
  if n == 1 and m == 1:
    return 1
  elif n == 1:
    return m - 2
  elif m == 1:
    return n - 2
  else:
    return (n-2)*(m-2)
  
print(solve(N,M))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    n ,m = I2()
    if n == 2 or m == 2:
        print(0)
    else:
        print(max(1, n - 2)*max(1, m - 2))

Submission status: Accepted

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

n -= 2
m -= 2

ans = 0

if n == 0 or m == 0:
    ans = 0

elif n == -1 and m == -1:
    ans = 1

elif n == -1 or m == -1:
    ans = max(n, m)

else:
    ans = n * m

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, m = map(int, input().split())
a = max(n, m)
b = min(n, m)
if b == 1:
    print((a - 2) if a > 1 else 1)
elif b == 2:
    print(0)
else:
    print((a - 2) * (b - 2))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy
 
## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))
 
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()

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


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



    

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""



"""

Submission status: Accepted

Solution code:
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=1,1の場合に限ってなんかよくわからんが表にしてたのが原因でした ジャッジは悪くない
n, m = map(int, input().split())
if n == m == 1:
    print(1)
elif n == 1 or m == 1:
    print(max(n, m) - 2)
else:
    print(n * m - (n * 2 + (m - 2) * 2))

Submission status: Accepted

Solution code:
# これ灰difじゃないか？
# 各マス偶数回なら表 奇数回なら裏 -> 角は偶数回（4回）だし縁も偶数回（6回）だけどソレ以外は9回
# n, m = 1, 1の場合を忘れていてWA -> なんかしらんけどちがうっぽい 意味不明 （そもそも1,1のテストケースないんじゃないかこれ
# マジで納得がいかねぇ
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())


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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n,m = readInts()
if n==1:
	if m==1:
		print(1)
		exit()
	print(m-2)
	exit()
if m==1:
	print(n-2)
	exit()

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

Submission status: Accepted

Solution code:
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, m = MAP()

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

Submission status: Accepted

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

# In[7]:


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


# In[8]:


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


# In[ ]:

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

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

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,M = I()
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:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, M = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    if N==1 and M==1:
        print(1)
        return
    if N==1 or M==1:
        print(max(N-2,M-2))
        return 
    
    ans=0

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

    print(ans)



if __name__ == "__main__":
    main()

Submission status: Accepted

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

if N == 1 and M == 1:
    print(1)
elif N == 1 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:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))

n,m = iim()

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

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
if n==1 and m==1:
  ans=1
  print(ans)
  exit()

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
# from collections import defaultdict, deque
# import math
# import copy
# from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 1000000007

def solve():
    n,m = getList()
    if n == 1 and m == 1:
        print(1)
        return
    if n == 1:
        print(m - 2)
        return
    if m == 1:
        print(n - 2)
        return

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

    return


def main():
    n = getN()
    for _ in range(n):
        solve()
if __name__ == "__main__":
    # main()
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
lst=map(int,input().split())
lst=sorted(lst)
m=lst[0]
n=lst[1]

if m!=1:
    ans=m*n-2*(m+n)+4
    print(ans)
else:
    if n==1:
        print(1)
    else:
        print(n-2)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = 0 
if n>=3 and m>=3:
    ans = n*m - ((n+m)*2-4)

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

print(ans)

Submission status: Accepted

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

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

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:
n,m = list(map(int, input().split()))
# 隅は必ず表
# 辺は行か列なら1なら裏、以外は表
# 上記以外は裏

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


def read():
    N, M = map(int, input().strip().split())
    return N, M


def solve(N, M):
    if N > M:
        N, M = M, N
    if N == 1 and M == 1:
        return 1
    elif N == 1:
        return M - 2
    else:
        return (N-2) * (M-2)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

Solution code:
# arc091_a.py
# def canGo(y,x):
#     if x>=0 and y>=0 and x<W and y<H:
#         return True
#     return False

# def operate(h,w):
#     dx = [-1,0,1]
#     dy = [-1,0,1]
#     for x in dx:
#         for y in dy:
#             if canGo(h+y,w+x):
#                 print("can go",h+y,w+x)
#                 glid[h+y][w+x] += 1


H,W = map(int,input().split())
h = H-2
w = W-2
if H==1:
    h=1
if W==1:
    w=1
print(h*w)
# glid = [[0]*W for _ in range(H)]
# print(glid)
# print("#######")
# for i in range(H):
#     for j in range(W):
#         print(i,j)
#         operate(i,j)
# print(glid)