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
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
if N==1:
  N+=2
if M==1:
  M+=2
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 and m == 1:
  print(1)
elif (n == 1 and m == 2) or (n == 2 and m == 2) or (n == 2 and m == 3):
  print(0)
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 == 1:
  print(1)
elif n == 1:
  print(m-2)
elif m == 1:
  print(n-2)
elif n == 2 or m == 2:
  print(0)
else:
  print(n*m -(n+m-2)*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, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N, M = MAP()
if N*M == 1:
	print(1)
elif N == 1 or M == 1:
	print(max(N, M)-2)
	exit()
else:
	C = (N+M-2)*2
	print(N*M-C)

Submission status: Accepted

Solution code:
def solve(n, m):

    return (n-2 if n-2 >= 0 else 1) * (m-2 if m-2 >= 0 else 1)

if __name__ == "__main__":
    n, m = [int(i) for i in input().split()]
    print(solve(n, m))

Submission status: Accepted

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

Submission status: Accepted

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

elif m==1 and n>1:
    print(n-2)
    
elif n==1 and m==1:
    print(1)

Submission status: Accepted

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

Submission status: Accepted

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

n = (n + 2) if n == 1 else n
m = (m + 2) if m == 1 else m

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n, m = mi()
    if n == 1 and m == 1:
        print(1)
    elif n == 1:
        print(m - 2)
    elif m == 1:
        print(n - 2)
    else:
        print((n - 2) * (m - 2))



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
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:
    a = max(0,m-2)
    b = max(0,n-2)
    print(a*b)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N, M = getNM()
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 resolve():
	n, m = map(int, input().split())
	print(abs(n-2) * abs(m-2))
resolve()

Submission status: Accepted

Solution code:
def main():
    N, M = list(map(int, input().split(' ')))
    N, M = min([N, M]), max([N, M])
    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))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n = n//a
    count += 1
  if a**count == n:
    return count
  else:
    return count+1

#############
# Main Code #
#############

N,M = IL()
if N==M==1:
  PE(1)
if N==1:
  PE(M-2)
if M==1:
  PE(N-2)
P((N-2)*(M-2))

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7


n,m=MI()
if n>m:
    n,m=m,n
#print(n)
if n==1:
    if m==1:
        ans=1
    else:
        ans=m-2
else:
    ans=n*m-2*(n+m-2)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
if n == m == 1:
  print(1)
elif n == 1 or m == 1:
  print(m+n-3)
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)
  elif n == 1 or m == 1:
    print(max(n-2, 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 == 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
import re
import math
from collections import defaultdict
from collections import deque
from fractions import Fraction
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(n)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_pow(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def getbin(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def get_primes(n,type="int"):
    if n==0:
        if type=="int":return []
        else:return [False]
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def pm(x):
    return x//abs(x)
def inputintlist():
    return list(map(int,input().split()))
######################################################################################################


H,W=map(int,input().split())


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu May 14 00:52:36 2020

@author: shinba
"""

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

ans = 0

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

Submission status: Accepted

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

min_NM = min(N,M)
max_NM = max(N,M)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,M=map(int,input().split())
    if N==M==1:
        ans=1
    elif N==1 or M==1:
        ans=N*M-2
    else:
        ans=(N-2)*(M-2)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

if n == 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:
H,W = map(int, input().split())
if H == W == 1:
    print(1)
    exit()
if H == 1 or W == 1:
    print (max(W,H)-2)
    exit()
print(W*H - (2*H+2*W-4))

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


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

Submission status: Accepted

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

    if n == 1 or m == 1:
        ans = max(0, max(n, m) - 2)
        print(ans)
        return
    else:
        x = max(0, n - 2)
        y = max(0, m - 2)
        ans = x * y
        print(ans)
        return


if __name__ == '__main__':
    main()

Submission status: Accepted

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


def solve(N: int, M: int):
    if N < M:
        N, M = M, N
    if N == 1:
        return 1
    if M == 1:
        return N - 2
    return (N - 2) * (M - 2)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    print(solve(N, M))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


show_flg = False
# show_flg = True


def main():
    N, M = MI()

    # graph = [[1] * (M+2) for i in range(N+2)]
    # for i in range(1, N+1):
    #     for j in range(1, M+1):
    #         for v in product([0, -1, 1], repeat=2):
    #             graph[v[0] + i][v[1] + j] = 1 - graph[v[0] + i][v[1] + j]

    # ans = 0
    # for i in range(1, N+1):
    #     for j in range(1, M+1):
    #         if graph[i][j] == 0:
    #             ans += 1

    # print(ans)

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
h,m=map(int,input().split());print((h-2)*(m-2)if h>=2 and m>=2 else 1 if h==m==1 else h+m-3)

Submission status: Accepted

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

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:
h, w = list(map(int, input().split()))
# b = list(map(int, input().split()))
if h == 1 and w == 1:
    print(1)
elif h == 1:
    print(w-2)
elif w == 1:
    print(h-2)
else:
    print(h*w-h*2-(w-2)*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:
def main():
    N, M = map(int, input().split())
    if N == 1:
        if M > 2:
            print(M-2)
        elif M == 2:
            print(0)
        else:
            print(1)
    elif M == 1:
        if N > 2:
            print(N-2)
        elif N == 2:
            print(0)
        else:
            print(1)
    elif N == 2 or M == 2:
        print(0)
    else:
        print((N-2)*(M-2))
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

def main():
    N, M = map(int, readline().rstrip().split())
    if N == 1 and M == 1:
        print(1)
        return
    if N == 1 or M == 1:
        print(max(N, M) - 2)
        return
    print((N-2) * (M-2))
    return


if __name__ == '__main__':
    main()