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:
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N, M = (int(_) for _ in input().split())
    if N==1 and M==1:
        print(1)
        return
    if N==1 or M==1:
        print(N*M - 2)
        return 
    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:
    ans = (n - 2) * (m - 2)
elif n > 1 and m == 1:
    ans = n - 2
elif n == 1 and m > 1:
    ans = m - 2
else:
    ans = 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

from math import *
from itertools import *
from collections import *
from bisect import *


if __name__ == '__main__':
    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:
        center = n*m - 2*n - 2*m + 4
        print(center)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
if N == M == 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().rstrip().split(' '))

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

Submission status: Accepted

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


def solve(N: int, M: int):
    a = (N-2) if N >= 2 else 1
    b = (M-2) if M >= 2 else 1
    print(a*b)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    solve(N, M)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a, b =map(int, input().split())  #複数数値入力

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

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:

str = input().split()
N = int(str[0])
M = int(str[1])

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

Submission status: Accepted

Solution code:

def solve(N, M):
    # 1 2
    # 3 4

    # 1 2
    # 3 4
    #
    # (0)    (1)
    # 1 2    1 2 3
    # 3 4    4 5 6
    # 5 6    7 8 9
    def cut(n):
        if n == 1:
            return 1
        elif n == 2:
            return 0
        return n - 2

    return cut(N) * cut(M)

N, M = [int(x) for x in input().split()]
print(solve(N, M))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,m=LI()
  return abs((m-2)*(n-2))

print(main())

Submission status: Accepted

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


if M < N:
    N, M = M, N

if N == 1:
    if M == 1:
        a = 1
    else:
        a = max(M-2, 0)
else:
    a = max(0, N-2) * max(0, 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 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())
print(abs(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)
    quit()
if N>M:
    M,N=N,M
if N==1:
    print(max(0,M-2))
    quit()
if N==2:
    print(0)
    quit()
print(N*M-(2*N+2*M-4))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


def solve(N: int, M: int):
    if N > M:
        N, M = M, N
    ret = 0
    if N == 1:
        if M == 1:
            ret = 1
        else:
            ret = M - 2
    else:
        ret = (N - 2) * (M - 2)
    print(ret)
    return


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
    solve(N, M)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = max(N-2, 0) * max(M-2, 0)

if N == 1 and M == 1:
        ans = 1
elif N == 1:
    ans = M - 2
elif M == 1:
    ans = N - 2

print(ans)

Submission status: Accepted

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

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

elif n == 2 or m == 2:
    print(0)

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


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


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)


###############################################################################


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

    if n == 1 and m == 1:
        print(1)
        return
    if n == 1 or m == 1:
        print(max([n - 2, m - 2, 0]))
        return
    if n == 2 or m == 2:
        print(0)
        return

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

Submission status: Accepted

Solution code:


def main():
    high, width = map(int, input().split())
    min_data = min(high, width)
    max_data = max(high, width)

    if min_data == 1:
        if max_data == 1:
            print(1)
        elif max_data == 2:
            print(0)
        else:
            print(max_data - 2)
    elif min_data == 2:
        print(0)
    else:
        print((high - 2) * (width - 2))



if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0
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())
ans = 0
if N > 1 and M > 1:
    ans = (N-2) * (M-2)

elif N==1 and M==1:
    ans = 1
else:
    ans = max(N, M) - 2
print(ans)

Submission status: Accepted

Solution code:
#ABC090-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,m=IL()
if n==1 and m==1:
    print(1)
elif n==1 or m==1:
    print(max(0,n-2,m-2))
else:
    print(max(0,(n-2)*(m-2)))

Submission status: Accepted

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

Submission status: Accepted

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


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


def submit():
    # 1 * N の場合
    # 1*1 -> 1
    # 1*2以上の場合、両端は表、ほかは裏

    # 2以上 * Nの場合
    # 角、辺は表、ほかは裏になる

    n, m = read_input()
    short_side = min(n, m)
    long_side = max(n, m)

    if short_side == 1:
        if long_side == 1:
            print(1)
        else:
            print(long_side - 2)
    else:
        # 角
        corners = 4
        sides = 2 * (short_side - 2) + 2 * (long_side - 2)
        insides = n * m - corners - sides

        print(insides)



if __name__ == '__main__':
    submit()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def calc(n, m):
    if n < 1 or m < 1:
        return 0
    elif n == 1 and m != 1:
        return m-2
    elif n != 1 and m == 1:
        return n-2
    else:
        return n * m -(2 * (m + n - 2))
print(calc(N,M))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split());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))

Submission status: Accepted

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

"""
1

44
44

464
696
464

1
2
1

121
"""

Submission status: Accepted

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

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

Submission status: Accepted

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


def solve(N: int, M: int):
    print(abs(N-2)*abs(M-2))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    solve(N, M)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
# 隣接するマスの数が偶数→裏
# 隣接するマスの数が奇数→表
# 隣接するマスの数が偶数のマスの数が答え

# 2*2以上なら辺上にないマスが全てそう
if N == 1 and M == 1:
    print(1)
elif N == 1:
    print(M - 2)
elif M == 1:
    print(N - 2)
else:
    print(N*M - 2*N - 2*M + 4)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

x=min(m,n)
y=max(m,n)

if x==y==1:
	print 1
elif x==1:
	print y-2
elif x==2:
	print 0
elif x>=3:
	print (y-2)*(x-2)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if n == 1 and m == 1:
    ans = 1
elif n == 1:
    ans = m-2
elif m == 1:
    ans = n-2
elif n == 2 or m == 2:
    ans = 0
else:
    ans = (n-2)*(m-2)

print(ans)

Submission status: Accepted

Solution code:
N, M = 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:
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 -*-

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

back = (N*M)-2*N-2*M+4
if back< 0:
    back*=-1
print(back)

Submission status: Accepted

Solution code:
a, b = [int(item) for item in input().split()]

if a >= 2 and b >= 2:
  print((a-2) * (b-2))
else:
  if a == 1 and b == 1:
    print(1)
  elif a == 1:
    print(b-2)
  elif b == 1:
    print(a-2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
if n==2 or m==2:
  print(0)
  exit()
if n==1 and m==1:
  print(1)
  exit()
if n==1 or m==1:
  k=max(n,m)
  print(k-2)
  exit()
print((n-2)*(m-2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# 2333332

#4666664
#4666664

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N, M = LI()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

def solve(n, m):
    if n > m:
        n, m = m, n
    
    if n * m == 1:
        return 1
    
    if n == 1:
        return n * m - 2
    
    return n * m - (n - 1) * 2 - (m - 1) * 2

main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def solve(string):
    n, m = map(int, string.split())
    if n == 1 and m == 1:
        return "1"
    elif n == 1 or m == 1:
        return str(max(n - 2, m - 2))
    elif n == 2 or m == 2:
        return "0"
    else:
        return str((n - 2) * (m - 2))


if __name__ == '__main__':
    print(solve(input()))

Submission status: Accepted

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

n_ = n - 2
if n_ < 0:
    n_ = 1

m_ = m - 2
if m_ < 0:
    m_ = 1

print(n_ * m_)

Submission status: Accepted

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import sys


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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

count = 0

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

print(count)

Submission status: Accepted

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

if N[1] == 1:
    print(1)
elif N[0] == 1:
    print(N[1] - 2)
else:
    print((N[0] - 2) * (N[1] - 2))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# ABC090C 3/18
import numpy as np
#import math
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0]*n
def zeros2(n, m): return [zeros(m)]*n # obsoleted zeros((n, m))で代替
def getIntLines(n): return [int(input()) for i in range(n)]
def getIntMat(n, m):  # n行に渡って、1行にm個の整数
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat
class Debug():
    def __init__(self):
        self.debug = True

    def off(self):
        self.debug = False

    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    N, M = getIntList()
    d.dmp((N, M))
    n = abs(N-2)
    m = abs(M-2)
    d.dmp((n,m),'n,m')
    return n*m


ans = prob()
if ans is None:
    pass
elif type(ans) == list and ans[0] == 'col':
    for elm in ans[1]:
        print(elm)
else:
    print(ans)