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: Wrong Answer

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


def solve(N: int, M: int):
    if N < M:
        N, M = M, N
    if M == 1:
        return N - 2
    if N == 1:
        return 1
    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: Wrong Answer

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


def solve(N: int, M: int):
    if N < M:
        N, M = M, N
    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: Wrong Answer

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if h == 1:
    print(w-2)
elif w == 1:
    print(h-2)
else:
    print(h*w-h*2-(w-2)*2)

Submission status: Wrong Answer

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

if h > 1:
    print(h*w-h*2-(w-2)*2)
else:
    print(w-2)

Submission status: Wrong Answer

Solution code:

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

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
ans = 0
if n > m:
    n, m = m, n
if 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: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b = map(int, input().split())

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

Submission status: Wrong Answer

Solution code:
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
DP2 = lambda d1, d2: [[INIT_VAL]*d2 for _ in range(d1)]
DP3 = lambda d1, d2, d3: [[[INIT_VAL]*d3 for _ in range(d2)] for _ in range(d1)]

def main():
    n, m = MII()
    if n > 2 and m > 2:
        print((n-2)*(m-2))
    elif n == 1 and m > 2:
        print(m-2)
    elif n > 2 and m == 1:
        print(n-2)
    elif n == m == 2:
        print(0)
    else:
        print(1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc090/tasks/arc091_a
# 15:17-15:22 done


def main():
    n, m = map(int, input().split())
    return (n-2)*(m-2)


print(main())

Submission status: Wrong Answer

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

if mn == 1:
    if mx == 1:
        print(1)
    else:
        print(m - 2)
elif mn >= 2:
    print((mx - 2) * (mn - 2))

Submission status: Wrong Answer

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

if mn == 1:
    if mx == 1:
        print(0)
    elif mx == 2:
        print(2)
    else:
        print(m - 2)
elif mn >= 2:
    print((mx - 2) * (mn - 2))

Submission status: Wrong Answer

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

if mn == 1:
    print(max(0,mx - 2))
elif mn >= 2:
    print((mx - 2) * (mn - 2))

Submission status: Wrong Answer

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

if mn == 1:
    print(mx - 2)
elif mn >= 2:
    print((mx - 2) * (mn - 2))

Submission status: Wrong Answer

Solution code:
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,m = readInts()
    """
    N <= M
    N = 1かつ、M = 1のとき、1枚だけあるカードは1毎裏返されるので、答えは1でｓ。
    N = 1かつ M ≠ 1のとき、 M 枚のカードのうち両端のカードは2回、それ以外のカードは
    3回裏替えされるので、答えはM-2
    N >= 2のとき、 N <= M より M >= 2で、このとき、
    ・四隅のカードは4回、　# 表になる
    ・それ以外のカードは週上のカードは6回 # 表になる
    ・それ以外のカードは9回
    裏返されるので、答えは、(N-2)(M-2)
    """

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

Submission status: Wrong Answer

Solution code:
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,m = readInts()
    """
    N <= M
    N = 1かつ、M = 1のとき、1枚だけあるカードは1毎裏返されるので、答えは1でｓ。
    N = 1かつ M ≠ 1のとき、 M 枚のカードのうち両端のカードは2回、それ以外のカードは
    3回裏替えされるので、答えはM-2
    N >= 2のとき、 N <= M より M >= 2で、このとき、
    ・四隅のカードは4回、　# 表になる
    ・それ以外のカードは週上のカードは6回 # 表になる
    ・それ以外のカードは9回
    裏返されるので、答えは、(N-2)(M-2)
    """

    
    print((n-2) * (m-2))
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if n > 2 and m > 2:
  print((n-2)*(m-2))
elif n == 2 or m == 2:
  print(0)
else:
  print(max([0, m-2, n-2]))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, M = [int(x) for x in input().split()]
x = (abs(3-N)+1)*(M-2)
y = (abs(3-M)+1)*abs((N-2))
print(min(x,y))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans = 0


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

elif (n == 2 and m >= 3) or (m == 2 and n >= 3):
    ans = 0
    print(ans)

elif (n == 1 and m >= 3) or (m == 1 and n >= 3):
    ans = n * m - 2
    print(ans)

elif n == 2 and m == 2:
    ans = 0
    print(ans)
    
else:
    ans = 0
    print(ans)

Submission status: Wrong Answer

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

resolve()

Submission status: Wrong Answer

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

if N > M:
    N, M = M, N

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

print(N * M)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

def Flip_and_Flip(n , m):

    ans = 0

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

    return ans

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def calculate(n,m):

    if n == 1:
        return m - 2

    if m == 1:
        return n - 2

    return (n - 2) * (m - 2)
result = calculate(N,M)
print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

naka = max(0, total -((n+m)*2-4))
#hashi = max(0, (n+m)*2-4-4)
#sumi = 2 if (n==1 and m>1) or (m==1 and n>1) else 4

print(naka)
#print(hashi+sumi)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n,m = MAP()
if n > 1 and m > 1:
    print((n - 2) * (m - 2))
elif n > 1 and m == 1:
    print(n - 2)
elif n == 1 and m > 1:
    print(m - 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
w, h = map(int, input().split())
 
count = 0
 
if w == h == 1:
    count = 0
elif w == 1:
    count = h-2
else:
    count = (w - 2) * (h - 2)
    
print(count)

Submission status: Wrong Answer

Solution code:
w, h = map(int, input().split())
 
count = 0
 
if w == h == 1:
    count = 0
elif w == 1 or h == 1:
    count = max(w,h)-2
else:
    count = (w - 2) * (h - 2)
    
print(count)

Submission status: Wrong Answer

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

count = 0

if w == h == 1:
    count = 0
elif w < 3 or h < 3:
    count = w*h - min(w,h)*2
else:
    count = (w - 2) * (h - 2)
    
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if n==2 or m==2:
  print(0)
  exit()

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if n == 1 or m == 1:
    n, m = sorted([n, m])
    print(max(n*m-2, 0))
else:
    print(n*m-2*(n+m)+4)

Submission status: Wrong Answer

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

if n == 1 or m == 1:
    n, m = sorted([n, m])
    print(n*m-2)
else:
    print(n*m-2*(n+m)+4)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# 角のマスは4回、端のマスは6回（表になる）
# それ以外のマスであればカードを裏返す回数は9回（裏になる）
n, m = map(int, input().split())
if n == 1 or m == 1:
    print(n*m - 2)
else:
    print(n*m - 2*((n-1)+(m-1)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if n==1 or m==1:
  c = max(0, m-2)
  d = max(c, n-2)
  print(d)
else:
  print((n-2)*(m-2))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    width, height = map(int, input().split(" "))
    if width * height == 1:
        print(1)
    elif width == 1:
        print(height - 2, 0)
    elif height == 1:
        print(width - 2)
    else:
        print((height - 2) * (width - 2))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, m = [int(i) for i in input().split()]
# 偶数回裏返されるカードは表に
# 奇数回裏返されるカードは裏になる
# 各マスのカードが何回裏返されるかで最後に裏になっている枚数を計算できる
if n == m == 1:
    print(1)
elif n == 1 and m != 1:
    print(m - 2)
elif 2 <= n <= m:
    print((n - 2) * (m - 2))
else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys

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

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

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

Submission status: Wrong Answer

Solution code:
import sys

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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


#A = [[0] * W for i in range(H)]
#C = ["o" * W for i in range(H)] 
#C = ["#"*(W+2)] + ["#"+C[i]+"#" for i in range(H)] + ["#"*(W+2)]
#dx = [1, 1, 0, -1, -1, -1, 0, 1]
#dy = [0, 1, 1, 1, 0, -1, -1, -1]
#
#for h in range(H):
#    for w in range(W):
#        for i in range(8):
#            if C[h+1+dx[i]][w+1+dy[i]] == "o":
#                A[h][w] += 1
#ans = 0
#for h in range(H):
#    for w in range(W):
#        if A[h][w] % 2 == 0:
#            ans += 1
#
#print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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


#A = [[0] * W for i in range(H)]
#C = ["o" * W for i in range(H)] 
#C = ["#"*(W+2)] + ["#"+C[i]+"#" for i in range(H)] + ["#"*(W+2)]
#dx = [1, 1, 0, -1, -1, -1, 0, 1]
#dy = [0, 1, 1, 1, 0, -1, -1, -1]
#
#for h in range(H):
#    for w in range(W):
#        for i in range(8):
#            if C[h+1+dx[i]][w+1+dy[i]] == "o":
#                A[h][w] += 1
#ans = 0
#for h in range(H):
#    for w in range(W):
#        if A[h][w] % 2 == 0:
#            ans += 1
#
#print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N,M = [int(i) for i in input().split()]
if N == 1 and M != 1:
    print(M-2)
elif M == 1 and N != 1:
    print(N-2)
elif N == 1 and M == 1:
    print(0)
else :
    print((N-2) * (M-2))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N,M = [int(i) for i in input().split()]
if N == 1 :
    print(M-2)
elif M == 1 :
    print(N-2)
else :
    print((N-2) * (M-2))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
ans = N*M
if N < 3 and M < 3:
    print(0)
    exit()
#偶数回操作が行われるもの
even = 0
#奇数回操作が行われるもの
odd = 0
#答えはoddの値
if N<=M:
    if N==1:
        s = 2*N
        print(ans-s)
    else:
        s = 2*N+2*(M-2)
        print(ans-s)
else:
    if M==1:
        s = 2*M
        print(ans-s)
    else:
        s = 2*M+2*(N-2)
        print(ans-s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
cnt = 0
if n == 1 and m == 1:
  corner = 1
  wall = 0
if n > 1 and m > 1:
  corner = 4
  wall = max(0, n-2) * 2 + max(0, m-2) * 2
if n == 1 and m > 1:
  corner = 2
  wall = 0
if n > 1 and m == 1:
  corner = 2
  wall = 0
print(n * m - corner - wall)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if N > 2:
  N -= 2
  
if M > 2:
  M -= 2

print(N*M)

Submission status: Wrong Answer

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

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