Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

1 \leq N,M \leq 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

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

Sample Input 1

2 2

Sample Output 1

0

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

Sample Input 2

1 7

Sample Output 2

5

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

Sample Input 3

314 1592

Sample Output 3

496080



Sample input:
2 2


Sample output:
0

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = [int(i) for i in input().split()]
if N == 1 and M == 1:
	print(1)
elif N == 1 or M == 1:
	print(abs(N-M)-1)
else:
	print(N*M-2*N-2*M+4)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

if b >= 2:
    s = b - 2
else:
    s = 1
if a >= 2:
    t = a - 2
else:
    t = 1
q = s * t
print(q)

Submission status: Accepted

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

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

Submission status: Accepted

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

if (x[0]==1 and x[1]==1):
    print(1)    
    quit()
elif(x[0]==1):
    print(x[1]-2)    
    quit()
elif(x[1]==1):
    print(x[0]-2)    
    quit()

print((x[0]-2)*(x[1]-2)) 

quit()

Submission status: Accepted

Solution code:
import collections
from pprint import pprint as pp

ri = lambda: int(input())
ria = lambda: list(map(int, input().split()))

def func(N, M):
    num = 0
    cols = N*M
    if cols == 0:
        return 0
    if cols == 1:
        return 1
    if N == 1:
        return cols - 2
    if N == 2:
        return 0
    return (N-2) * (M-2)
    

l = ria()
N,M = min(l), max(l)
print(func(N,M))

Submission status: Accepted

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

if 1 in NM:
    if (max(NM)-2) >= 0:
        print(max(NM)-2)
    else:
        print(1)
elif 2 in NM:
    print(0)
else:
    print(NM[0]*NM[1]-(2*NM[0]+2*NM[1]-4))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, M = list(map(int, input().split()))
    if (N==1)and(M==1):
        return 1
    elif N == 1:
        return M-2
    elif M == 1:
        return N-2
    else:
        return N*M - (2*(N+M)-4)

if __name__ == '__main__':
    print(main())

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def c_flip(N, M):
    if N == 1 and M == 1:
        return 1
    elif N == 1 or M == 1:
        return max(N, M) - 2
    elif N == 2 or M == 2:
        return 0
    else:
        return N * M - (N * 2 + M * 2 - 4)
    return None

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

Submission status: Accepted

Solution code:
# coding=utf-8
line = input().split(" ")
n = int(line[0])
m = int(line[1])

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

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

Submission status: Accepted

Solution code:
import sys

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
N,M=map(int, raw_input().split())
if N==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*M-( (N+M)*2-4 )

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
nm = input().split()
n = int(nm[0])
m = int(nm[1])
print(abs((n-2)*(m-2)))

Submission status: Accepted

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

if a>1 and b>1:
  print((a-2)*(b-2))
elif a==1 and b==1:
  print(1)
else:
  print(max(a,b)-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 not n == 1:
  n -= 2

if not m == 1:
  m -= 2

print(n * m)

Submission status: Accepted

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

res = 0
if N == 1 or M == 1:
	if N == 1 and M == 1:
		res = 1
	elif N == 1:	# if M != 1
		res = M - 2
	elif M == 1: # if N != 1
		res = N - 2
else:	# if N != 1 and M != 1
	res = (N - 2) * (M - 2)

print(res)

Submission status: Accepted

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

if [N, M] == [1, 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:
    if m==1:
        print(1)
        exit()
    print(m-2)
    exit()
if m==1:
    print(n-2)
    exit()
print(n*m-(n*2+m*2-4))

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

Submission status: Accepted

Solution code:
n, m = map(int, raw_input().split())
if n + m == 2: print 1
elif n + m == 3: 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)
if N==1 and M!=1:
    print(M-2)
if M==1 and N!=1:
    print(N-2)
if N!=1 and M!=1:
    print((M-2)*(N-2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:




def main():
    temp=input()
    temp=list(map(int,list(temp.split(" "))))    
    a=int(temp[0])
    b=int(temp[1])
    c=a*b
    count=c-2*a-2*b+4
    if count<0:
        count*=-1
    print(count)


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

Submission status: Accepted

Solution code:
# C

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) + 4)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
n, m = map(int, input().split())
if n>1:
    n = n-2
if m>1:
    m = m-2
print(n*m)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
#N>=Mとして一般性を失わない
if N==M==1:
    print(1)
if N==1 and M>=2:
    print(M-2)
if N==2 and M>=2:
    print(0)
if N>=3 and M>=3:
    print((N-2)*(M-2)

Submission status: Runtime Error

Solution code:
def cnt_map(x,y):
    if 1<=x<=n-2 and 1<=y<=m-2:
        return 9
    else:
        cnt = 0
        for i in [-1,0,1]:
            for j in [-1,0,1]:
                if 0<=x+i<n and 0<=y+j<m:
                    cnt += 1
        return cnt

n,m = map(int,input().split())
chizu = [[0] * m for i in range(n)]
cnt = 0
for i in range(n):
    for j in range(m):
        cnt += cnt_map(i,j)%2
print(cnt)

Submission status: Runtime Error

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

NM = [[0]*(M+2) for _ in range(N+2)]

for i in range(1,N+1):
    for j in range(1,M+1):
        NM[i-1][j-1] = ~NM[i-1][j-1]
        NM[i-1][j-0] = ~NM[i-1][j-0]
        NM[i-1][j+1] = ~NM[i-1][j+1]
        NM[i-0][j-1] = ~NM[i-0][j-1]
        NM[i-0][j-0] = ~NM[i-0][j-0]
        NM[i-0][j+1] = ~NM[i-0][j+1]
        NM[i+1][j-1] = ~NM[i+1][j-1]
        NM[i+1][j-0] = ~NM[i+1][j-0]
        NM[i+1][j+1] = ~NM[i+1][j+1]

print(NM)

ans = 0
for k in range(1,N+1):
    ans += sum(NM[k][1:M+1])

print(-1*ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def change(c):
    if c:
        return False
    else:
        return True


# input
N, M = map(int, input().split())
card = [[True for i in range(N)] for j in range(M)]

for i in range(N):
    for j in range(M):
        target = card[i]
        target[j] = change(target[j])
        if j - 1 >= 0:
            target[j - 1] = change(target[j - 1])
        if j + 1 < M:
            target[j + 1] = change(target[j + 1])

        if i - 1 >= 0:
            target = card[i - 1]
            target[j] = change(target[j])
            if j - 1 >= 0:
                target[j - 1] = change(target[j - 1])
            if j + 1 < M:
                target[j + 1] = change(target[j + 1])

        if i + 1 < N:
            target = card[i + 1]
            target[j] = change(target[j])
            if j - 1 >= 0:
                target[j - 1] = change(target[j - 1])
            if j + 1 < M:
                target[j + 1] = change(target[j + 1])

print(sum([i.count(False) for i in card]))

Submission status: Runtime Error

Solution code:
def f(x):
    if x == 0:
        return 1
    elif x == 1:
        return 0

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

a = [[0]*(M+2) for _ in range(N+2)]
for i in range(N):
    for j in range(M):
        a[i][j] = f(a[i][j])
        a[i][j+1] = f(a[i][j+1])
        a[i][j+2] = f(a[i][j+2])
        a[i+1][j] = f(a[i+1][j])
        a[i+1][j+1] = f(a[i+1][j+1])
        a[i+1][j+2] = f(a[i+1][j+2])
        a[i+2][j] = f(a[i+2][j])
        a[i+2][j+1] = f(a[i+2][j+1])
        a[i+2][j+2] = f(a[i+2][j+2])
print(sum(a[1:N+1, 1:M+1]))

Submission status: Runtime Error

Solution code:
def f(x):
    if x == 0:
        return 1
    elif x == 1:
        return 0

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

a = [[0]*(M+2) for _ in range(N+2)]
for i in range(N):
    for j in range(M):
        for k in range(3):
            for l in range(3):
                a[i+k][j+l] = f(a[i+k][j+l])
print(sum(a[1:N+1, 1:M+1]))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
G = [[1]*M for _ in range(N)]

x = (-1, 0, 1)
y = (-1, 0, 1)
for i in range(N):
    for j in range(M):
        for dx in x:
            for dy in y:
                if 0 <= i+dy <= N-1 and 0 <= j+dx <= M-1:
                    G[i+dy][j+dx] *= -1

ans = 0
for g in G:
    ans += g.count(-1)
print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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: Runtime Error

Solution code:
# ABC090C

import numpy as np

n, m = map(int, input().split())
board = np.zeros((n + 2, m + 2), dtype=bool)
board[1:n + 1, 1:m + 1] = np.ones((n, m), dtype=bool)
for i in range(1, n + 1):
    for j in range(1, m + 1):
        board[i-1, j-1] = not board[i-1, j-1]; board[i-1, j] = not board[i-1, j]; board[i-1, j+1] = not board[i-1, j+1]
        board[i  , j-1] = not board[i  , j-1]; board[i  , j] = not board[i  , j]; board[i  , j+1] = not board[i  , j+1]
        board[i+1, j-1] = not board[i+1, j-1]; board[i+1, j] = not board[i+1, j]; board[i+1, j+1] = not board[i+1, j+1]
count = 0
for i in range(1, n + 1):
    for j in range(1, m + 1):
        if board[i, j] == False:
            count += 1
print(count)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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()
    LIST = [[0] * m for _ in range(n)]
    #print(*LIST)
    dx = [-1,-1,-1, 0, 0, 0, 1, 1, 1]
    dy = [-1, 0, 1,-1, 0, 1,-1, 0, 1]
    d = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,0],[0,1],[1,-1],[1,0],[1,1]]
    for y in range(n):
        for x in range(m):
            for ax,ay in d:
                nx = x + ax
                ny = y + ay
                if 0 <= nx < m and 0 <= ny < n:
                    if ax == 0 and ay == 0:
                        #print(ax,ay)
                        LIST[ny][nx] += 1
                    else:
                        LIST[ny][nx] -= 1
    ans = 0
    for i in range(n):
        ans += sum(1 for j in range(m) if LIST[i][j] % 2 != 0)
    print(ans)
if __name__ == '__main__':
  main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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: Runtime Error

Solution code:
n,m = map(int,input().split())
nm = ['#'] * n
nm.insert(0,0)
nm.insert(n+1,0)
nm = [nm]*m
nm.insert(0,[0]*(m+2))
nm.insert(m+1,[0]*(m+2))
ans = 0

for i in range(1,m+1):
    for j in range(1,n+1):
        cnt = 0
        if nm[i+1][j+1] == '#':
            cnt += 1
        if nm[i+1][j] == '#':
            cnt += 1
        if nm[i+1][j-1] == '#':
            cnt += 1
        if nm[i][j+1] == '#':
            cnt += 1
        if nm[i][j] == '#':
            cnt += 1
        if nm[i][j-1] == '#':
            cnt += 1
        if nm[i-1][j+1] == '#':
            cnt += 1
        if nm[i-1][j] == '#':
            cnt += 1
        if nm[i-1][j-1] == '#':
            cnt += 1
        if cnt % 2 != 0:
            ans+=1

print(ans)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
nm = ['#'] * n
nm.insert(0,0)
nm.insert(n+1,0)
nm = [nm]*m
nm.insert(0,[0]*(m+2))
nm.insert(m+1,[0]*(m+2))
total = []
ans = 0

for i in range(1,m+1):
    for j in range(1,n+1):
        cnt = 0
        if nm[i+1][j+1] == '#':
            cnt += 1
        if nm[i+1][j] == '#':
            cnt += 1
        if nm[i+1][j-1] == '#':
            cnt += 1
        if nm[i][j+1] == '#':
            cnt += 1
        if nm[i][j] == '#':
            cnt += 1
        if nm[i][j-1] == '#':
            cnt += 1
        if nm[i-1][j+1] == '#':
            cnt += 1
        if nm[i-1][j] == '#':
            cnt += 1
        if nm[i-1][j-1] == '#':
            cnt += 1
        total.append(cnt)

for i in range(n*m):
    if total[i] % 2 != 0:
        ans += 1

print(ans)

Submission status: Runtime Error

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

def initTable(N,M):
    table = [['.'] * M for i in range(N)]
    return table

def flipCard(row, column, table):
    for r in range(3):
        for c in range(3):
            if row + (r-1) < 0 or column + (c-1) < 0:
                pass
            elif row + (r-1) >= N or column + (c-1) >= M:
                pass
            else:
                card = table[row + (r-1)][column + (c-1)]
                if card == '.':
                    card = '#'
                else :
                    card = '.'
                table[row + (r-1)][column + (c-1)] = card
    return table

table = initTable(N, M)

for row in range(N):
    for column in range(M):
        table = flipCard(row, column, table)
        
cnt = 0
for row in table:
    cnt += row.count('#')

print(cnt)

Submission status: Runtime Error

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: Runtime Error

Solution code:
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: Runtime Error

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

H, W = MAP()

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: Runtime Error

Solution code:
N, M = map(int, input().split())
NM = [[0]*N]*M
count = 0
# print(NM)
if N == 1 and M > 1:
    count = M-2
elif M == 1 and N > 1:
    count = N-2
elif N >= 2 or M >= 2:
    count = (N-2)*(M-2)

print(count)

Submission status: Runtime Error

Solution code:
n,m = map(int, input().split())
a = [[0]*m for i in range(n)]
ans = 0
if n == 1:
    if m == 1:
        ans = 1
    elif m == 2:
        ans = 0
    else:
        ans = m - 2

if n == 2:
    ans = 0

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



print(ans)

Submission status: Runtime Error

Solution code:
n,m = map(int, input().split())
a = [[0]*m for i in range(n)]
def rev(k):
    if k==1:
        return 0
    else:
        return 1
for i in range(n):
    for j in range(m):
        a[i][j] = rev(a[i][j])
        if j > 0:
            a[i][j-1] = rev(a[i][j-1])
        if j < m-1:
            a[i][j+1] = rev(a[i][j+1])
        if i > 0:
            a[i-1][j] = rev(a[i-1][j])
            if j > 0:
                a[i-1][j-1] = rev(a[i-1][j-1])
            if j < m-1:
                a[i-1][j+1] = rev(a[i-1][j+1])
        if i < n-1:
            a[i+1][j] = rev(a[i+1][j])
            if j > 0:
                a[i+1][j-1] = rev(a[i+1][j-1])
            if j < m-1:
                a[i+1][j+1] = rev(a[i+1][j+1])

ans = 0
for i in range(n):
    for j in range(m):
        ans += a[i][j]
print(ans)

Submission status: Runtime Error

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

if N == 1:
    print(max(M - 2, 0)))
elif M == 1:
    print(max(M - 2, 0)))
elif N == 1 and M == 1:
    print(1)
else:
    # Number of cards appearing "back"
    # = (N-2)*(M-2)
    print(max((N - 2) * (M - 2), 0))

"""
# An experiment
n_count_map = [[0 for _ in range(M)] for _ in range(N)]


def update(x, y):
    # Count
    n_count_map[y][x] += 1
    if y + 1 < N:
        n_count_map[y + 1][x] += 1
    if y - 1 >= 0:
        n_count_map[y - 1][x] += 1
    if x + 1 < M:
        n_count_map[y][x + 1] += 1
    if x - 1 >= 0:
        n_count_map[y][x - 1] += 1
    if y + 1 < N and x + 1 < M:
        n_count_map[y + 1][x + 1] += 1
    if y - 1 >= 0 and x - 1 >= 0:
        n_count_map[y - 1][x - 1] += 1
    if y + 1 < N and x - 1 >= 0:
        n_count_map[y + 1][x - 1] += 1
    if y - 1 >= 0 and x + 1 < M:
        n_count_map[y - 1][x + 1] += 1


for n in range(N):
    for m in range(M):
        update(m, n)

print(n_count_map)
"""

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n, m;
  cin >> n >> m;

  if (n>=2 && m>=2) {
      cout << n*m - (n-2)*2 - (m-2)*2 - 4 << endl;
  }
  else if (n==1 && m==1) {
      cout << 1 << endl;
  }
  else if (n==1 && m>=2) {
      cout << m-2 << endl;
  }
  else {
      cout << n-2 << endl;
  }
  return 0;
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;

  if (n>=2 && m>=2) {
      cout << n*m - (n-2)*2 - (m-2)*2 - 4 << endl;
  }
  else if (n==1 && m==1) {
      cout << 1 << endl;
  }
  else if (n==1 && m>=2) {
      cout << m-2 << endl;
  }
  else {
      cout << n-2 << endl;
  }
  return 0;
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;

  if (n>=2 && m>=2) {
      cout << n*m - (n-2)*2 - (m-2)*2 - 4 << endl;
  }
  else if (n==1 && m==1) {
      cout << 1 << endl;
  }
  else if (n==1 && m>=2) {
      cout << m-2 << endl;
  }
  else {
      cout << n-2 << endl;
  }
}

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
if N > M:
    tmp = N
    N = M
    M = tmp
fields = [[0] * (M+2) for i in range(N+2)]

# for i in range(1,N+1):
#     for j in range(1,M+1):
#         for k in range(-1,2):
#             for l in range(-1,2):
#                 fields[i+k][j+l] += 1

# for f in fields:
#     print(*f)

n9 = max(0,N-2)*max(0,M-2)
n1 = 4
n2 = 8
n3 = max(0,N-2)*2 + max(0,M-2)*2
n6 = max(0,N-2)*2 + max(0,M-2)*2
n4 = 4

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
c = [[0]*n for _ in range(m)]

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: Runtime Error

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

def prob(n,m):
	if n == 1 and m == 1:
	  return 1
	
	if (n == 1 or m == 1) and n + m == 3:
  		return 0

	if (n == 1 or m == 1) and n + m >= 3:
  		longer = max(n,m)
  		mannaka = longer - 2
  		hashi = 2
  		answer = mannaka
  
	if n == 2 and m == 2:
  		return 0

	if (n == 2 or m == 2) and (n + m) >= 5:
  		longer = max(n,m)
  		shorter = min(n,m)
  		mannaka = longer - 4
  		hashi = 4
  		return 0

	if n >= 3 and m >= 3:
  		longer = max(n,m)
  		shorter = min(n,m)
  		hashi = 4
  		hen = (longer * 2) -4 + (shorter * 2) -2
        mannaka = longer * shorter - (hashi + hen)
        return mannaka
 
print(prob(n,m))

Submission status: Runtime Error

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