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

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

first = N*M
ans = 0

def reverse(x):
    if x == 0:
        return(1)
    else:
        return(0)


field = [[0]*(M+2) for i in range(N+2)]

for i in range(1, N+1):
    for j in range(1, M+1):
        field[i-1][j-1] = reverse(field[i-1][j-1])
        field[i][j-1] = reverse(field[i][j-1])
        field[i+1][j-1] = reverse(field[i+1][j-1])
        field[i-1][j] = reverse(field[i-1][j])
        field[i][j] = reverse(field[i][j])
        field[i+1][j] = reverse(field[i+1][j])
        field[i-1][j+1] = reverse(field[i-1][j+1])
        field[i][j+1] = reverse(field[i][j+1])
        field[i+1][j+1] = reverse(field[i+1][j+1])
ans = 0

for i in range(1, N+1):
    ans += sum(field[i][1:M+1])

print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
_N, _M = [int(_) for _ in input().split()]


def calc(N, M):
    ans = 0

    hasikko = [0]
    if M > 1:
        hasikko.aapned(M - 1)

    for i in hasikko:
        tmp = 1
        if M > i + 1:
            tmp += 1
        if N > 1:
            tmp += 1
        if N > 1 and M > i + 1:
            tmp += 1
        if N > 1 and i - 1 >= 0:
            tmp += 1
        if i > 0:
            tmp += 1

        ans += tmp % 2
        # print(tmp, ans)
    if M > 2 and N == 1:
        ans += M - 2

    if N >= 2:
        ans = ans * 2
    return ans


res = calc(_N, _M)

if _N >= 3:
    res += calc(_M, _N - 2)

if _N >= 3 and _M >= 3:
    res += (_N - 2) * (_M - 2)
print(res)

Submission status: Runtime Error

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

#表を0とする　カードの設定
G = [[0]*N for _ in range(M)]

#めくる
def turn(x,y):
    G[y][x] = (G[y][x]+1)%2
    if x > 0:
        G[y][x-1] = (G[y][x-1]+1)%2
        if y > 0:
            G[y-1][x-1] = (G[y-1][x-1]+1)%2
        if y < M-1:
            G[y+1][x-1] = (G[y+1][x-1]+1)%2
    if x < N-1:
        G[y][x+1] = (G[y][x+1]+1)%2
        if y > 0:
            G[y-1][x+1] = (G[y-1][x+1]+1)%2
        if y < M-1:
            G[y+1][x+1] = (G[y+1][x+1]+1)%2
    if y > 0:
        G[y-1][x] = (G[y-1][x]+1)%2
    if y < M-1:
        G[y+1][x] = (G[y+1][x]+1)%2
    return G

for i in range(N):
    for j in range(M):
        x = i
        y = j
        turn(x,y)

res = 0
for g in G:
    res += sum(g)
print(res)

Submission status: Runtime Error

Solution code:
import numpy as np
h,q=map(int,input().split())
#動きの確認code,0が裏,1を表
"""
box=[["*"]+["1"]*h+["*"] for i in range(q)]
box.insert(0,["*"]*(h+2))
box.append(["*"]*(h+2))
print(np.array(box))
for i in range(1,q+1):
    for j in range(1,h+1):
        try:
            seat=[[0,0],[0,1],[0,-1],[1,0],[1,1],[1,-1],[-1,0],[-1,1],[-1,-1]]
            for x,y in seat:
                xx=i+x
                yy=j+y
                if box[xx][yy]=="1":
                    box[xx][yy]="0"
                elif box[xx][yy]=="0":
                    box[xx][yy]="1"
                elif box[xx][yy]=="*":continue
        except:continue
print(np.array(box))
"""
if h==2 or q==2:print(0)
elif h==1 or q==1:
    if h!=1:print((h-2)*1)
    elif q!=1:print((q-2)*1)
    else:print(1)
else:
    print((h-2)*(q-2))

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

Submission status: Runtime Error

Solution code:
N,M = map(int,input())
# can't understand meaning
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: Runtime Error

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


void solve(long long N, long long M){
    if(N>=2&&M>=2)cout << (N-2)*(M-2) << endl;
    if(N<2&&M>=2) cout << (M-2) << endl;
    if(N>=2&&M<2) cout << (N-2) << endl;
    if(N<2&&M<2)  cout << 1 << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
reverse = [1]*(N*M)
num1 = [-M-1, -M, -M+1, -1, 1, M-1, M, M+1]
num2 = [-M, -M+1, 1, M, M+1]
num3 = [-M-1, -M, -1, M-1, M]
if N == M == 1:
    reverse[0] *= -1
else:
    for i in range(N*M):
        reverse[i] *= -1
        if (i % M) == 0:
            num = num2
        elif ((i + 1) % M) == 0:
            num = num3
        else:
            num = num1
        for j in num:
            if ((i + j) >= 0) and ((i + j) < (N * M)):
                reverse[i+j] *= -1
print(reverse.count(-1))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
reverse = [1]*(N*M)
num1 = [-M-1, -M, -M+1, -1, 1, M-1, M, M+1]
num2 = [-M, -M+1, 1, M, M+1]
num3 = [-M-1, -M, -1, M-1, M]
for i in range(N*M):
    #print(i, reverse)
    reverse[i] *= -1
    if (i % M) == 0:
        num = num2
    elif ((i + 1) % M) == 0:
        num = num3
    else:
        num = num1
    for j in num:
        if ((i + j) >= 0) and ((i + j) < (N * M)):
            reverse[i+j] *= -1
    #print(reverse)
#print(num)
#print(reverse)
print(reverse.count(-1))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
L=list([0]*M for _ in range(N))
if N>=2 and M>=2:
    print((N-2)*(M-2))
elif max(N,M)>=2:
    print(max(N,M)-2)
else:
    print(1)

Submission status: Runtime Error

Solution code:
from itertools  import product
N,M=map(int,input().split())
L=list([0]*M for _ in range(N))
if N>=2 and M>=2:
    print((N-2)*(M-2))
elif max(N,M)>=2:
    print(max(N,M)-2)
else:
    print(1)

Submission status: Runtime Error

Solution code:
from itertools  import product
N,M=map(int,input().split())
L=list([0]*M for _ in range(N))
ans=0
for x in range(N):
    for y in range(M):
        count=0
        for dx,dy in list(product([-1,0,1],repeat=2)):
            if 0<=x+dx<=N-1 and 0<=y+dy<=M-1:
                count+=1
        if count%2==1:
            ans+=1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

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

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
grid = [['#' for _ in range(m + 2)]]
for i in range(n):
    row = ['#'] + [True for _ in range(m)] + ['#']
    grid.append(row)
grid.append(['#' for _ in range(m + 2)])

dict = (
    (-1,-1),(-1, 0),(-1,1),
    (0,-1),(0, 0),(0,1),
    (1,-1),(1, 0),(1,1),
)

for i in range(1, n+1):
    for j in range(1, m+1):
        for d in dict:
            dy, dx = d
            y = i+dy
            x = j+dx
            if grid[y][x] != '#':
                grid[y][x] = not grid[y][x]
        

f = sum(grid, [])
print(f.count(False))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

input = sys.stdin.readline

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

x = np.ones((n+2, m+2))
kernel = -1 * np.ones((3,3))

for i in range(1,n+1):
    for j in range(1, m+1):

        temp = x[i-1:i+2, j-1:j+2]
        x[i-1:i+2, j-1:j+2] = temp * kernel

x = x[1:n+1, 1:m+1]

ans = np.sum(x<0)
print(ans)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

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

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

print(abs((a-2)*(b-2)))

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
a,b = map(int,input())
if a != 1:
  a -= 2
if b != 1:
  b -= 2
print(a * b)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

if n > m:
    k = n
    n = m
    m = k

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

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

elif n == 2:
    print(0)

Submission status: Runtime Error

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

if n>m:
	swap(n,m)

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

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())
cnt = 0
for i in range(a,b+1):
    c = list(str(i))
    if c[0] == c[4] and c[1]==c[3]:
        cnt +=1
print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np

N, M = [int(c) for c in input().split()]
F = np.zeros((N+2, M+2), dtype="int8")
C = F.copy()
c = np.ones((N, M), dtype="int8")
C[1:-1, 1:-1] += c

F[:-1, :] += C[1:, :]
F[1:, :] += C[:-1, :]
F[:, :-1] += C[:, 1:]
F[:, 1:] += C[:, :-1]
F[:-1, 1:] += C[1:, :-1]
F[1:, :-1] += C[:-1, 1:]
F[:-1, :-1] += C[1:, 1:]
F[1:, 1:] += C[:-1, :-1]

print(np.sum(np.where(F[1:-1, 1:-1] % 2, 0, 1)))

Submission status: Runtime Error

Solution code:
import numpy as np

N, M = [int(c) for c in input().split()]
F = np.zeros((N+2, M+2))
C = F.copy()
c = np.ones((N, M))
C[1:-1, 1:-1] += c

F[:-1, :] += C[1:, :]
F[1:, :] += C[:-1, :]
F[:, :-1] += C[:, 1:]
F[:, 1:] += C[:, :-1]
F[:-1, 1:] += C[1:, :-1]
F[1:, :-1] += C[:-1, 1:]
F[:-1, :-1] += C[1:, 1:]
F[1:, 1:] += C[:-1, :-1]

print(np.sum(np.where(F[1:-1, 1:-1] % 2, 0, 1)))

Submission status: Runtime Error

Solution code:
N, M = [int(c) for c in input().split()]
F = np.zeros((N+2, M+2))
C = F.copy()
c = np.ones((N, M))
C[1:-1, 1:-1] += c

F[:-1, :] += C[1:, :]
F[1:, :] += C[:-1, :]
F[:, :-1] += C[:, 1:]
F[:, 1:] += C[:, :-1]
F[:-1, 1:] += C[1:, :-1]
F[1:, :-1] += C[:-1, 1:]
F[:-1, :-1] += C[1:, 1:]
F[1:, 1:] += C[:-1, :-1]

print(np.sum(np.where(F[1:-1, 1:-1] % 2, 0, 1)))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a, b = map(int,input().split())
list(c) = [a,b]
c =  c.sort()
if a == 1:
    if b==1:
        print(b)
    else:
        print(b-2)
else:
    print((a-2) * (b-2))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

# initialize the cards array. True if the card shows Back side. False if the card shows Top side
arr = [ [False] * m ] * n

for i in range(n):
    for j in range(m):
        for a in [-1, 0, 1]:
            for b in [-1, 0, 1]:
                if (i-b >=0 and j-a >= 0) and (i-b < n and j-a < m):
                    arr[i-b][j-a] = not arr[i-b][j-a]

print(sum(sum(l) for l in arr))

Submission status: Runtime Error

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

# initialize the cards array. True if the card shows Back side. False if the card shows Top side
arr = [ [False] * m ] * n

for i in range(n):
    for j in range(m):
        for a in [-1, 0, 1]:
            for b in [-1, 0, 1]:
                if (i-b >=0 and j-a >= 0) and (i-b < n and j-a < m):
                    arr[i-b][j-a] = not arr[i-b][j-a]

print(arr)
print(sum(sum(l) for l in arr))

Submission status: Runtime Error

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

# initialize the cards array. True means the card shows back side
arr = [ [False] * m ] * n

for i in range(n):
    for j in range(m):
        for a in [-1, 0, 1]:
            for b in [-1, 0, 1]:
                if i-b >=0 and j-a >= 0:
                    try:
                        arr[i-b][j-a] = not arr[i-b][j-a]
                    except IndexError:
                        pass
        print(i,j, arr)

print(sum(sum(l) for l in arr))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
K = input().split()
N = int(K[0])
M = int(K[1])

hairetu = np.ones((N+2, M+2))

for i in range(M+2):
    hairetu[0][i] = 0
    hairetu[N+1][i] = 0
for i in range(N+2):
    hairetu[i][0] = 0
    hairetu[i][M+1] = 0

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):
                hairetu[i+k][j+l] = (-1) * hairetu[i+k][j+l]


count = 0

for i in range(1, N+1):
    for j in range(1, M+1):
        if hairetu[i][j] == -1:
            count += 1


print(count)

Submission status: Runtime Error

Solution code:
import numpy as np
K = input()
N = int(K[0])
M = int(K[1])

hairetu = np.ones((N+2, M+2))

for i in range(M+2):
    hairetu[0][i] = 0
    hairetu[N+1][i] = 0
for i in range(N+2):
    hairetu[i][0] = 0
    hairetu[i][M+1] = 0

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):
                hairetu[i+k][j+l] = (-1) * hairetu[i+k][j+l]


count = 0

for i in range(1, N+1):
    for j in range(1, M+1):
        if hairetu[i][j] == -1:
            count += 1


print(count)

Submission status: Runtime Error

Solution code:
import numpy as np
K = input()
print(K)
N = int(K[0])
M = int(K[1])

hairetu = np.ones((N+2, M+2))

for i in range(M+2):
    hairetu[0][i] = 0
    hairetu[N+1][i] = 0
for i in range(N+2):
    hairetu[i][0] = 0
    hairetu[i][M+1] = 0

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):
                hairetu[i+k][j+l] = (-1) * hairetu[i+k][j+l]


print(hairetu)
count = 0

for i in range(1, N+1):
    for j in range(1, M+1):
        if hairetu[i][j] == -1:
            count += 1


print(count)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
M = int(input())

hairetu = np.ones((N+2, M+2))

for i in range(M+2):
    hairetu[0][i] = 0
    hairetu[N+1][i] = 0
for i in range(N+2):
    hairetu[i][0] = 0
    hairetu[i][M+1] = 0

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):
                hairetu[i+k][j+l] = (-1) * hairetu[i+k][j+l]


print(hairetu)
count = 0

for i in range(1, N+1):
    for j in range(1, M+1):
        if hairetu[i][j] == -1:
            count += 1


print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    N, M = map(int , raw_input().split())
    A = [[1 for i in range(N)] for j in range(M)]
    d = 0
    for i in range(M):
        for j in range(N):
            c = 0
            if i+1 < M and j+1 < N:
                c += 1
            if i+1 < M:
                c += 1
            if i+1 < M and j-1 >= 0:
                c += 1
            if j+1 < N:
                c += 1
            c += 1
            if j-1 >= 0:
                c += 1
            if i-1 >= 0 and j+1 < N:
                c += 1
            if i-1 >= 0:
                c += 1
            if i-1 >= 0 and j-1 >= 0:
                c += 1
            if c % 2 == 1:
                d += 1
    print d

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    N, M = map(int , raw_input().split())
    A = [[1 for i in range(N)] for j in range(M)]
    d = 0
    for i in range(M):
        for j in range(N):
            c = 0
            if i+1 < M and j+1 < N:
                c += 1
            if i+1 < M:
                c += 1
            if i+1 < M and j-1 >= 0:
                c += 1
            if j+1 < N:
                c += 1
            c += 1
            if j-1 >= 0:
                c += 1
            if i-1 >= 0 and j+1 < N:
                c += 1
            if i-1 >= 0:
                c += 1
            if i-1 >= 0 and j-1 >= 0:
                c += 1
                if c % 2 == 1:
                    d += 1
    print d

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    N, M = map(int , raw_input().split())
    A = [[1 for i in range(N)] for j in range(M)]
    for i in range(M):
        for j in range(N):
            if i+1 < M and j+1 < N:
                A[i+1][j+1] *= -1
            if i+1 < M:
                A[i+1][j] *= -1
            if i+1 < M and j-1 >= 0:
                A[i+1][j-1] *= -1
            if j+1 < N:
                A[i][j+1] *= -1
            A[i][j] *= -1
            if j-1 >= 0:
                A[i][j-1] *= -1
            if i-1 >= 0 and j+1 < N:
                A[i-1][j+1] *= -1
            if i-1 >= 0:
                A[i-1][j] *= -1
            if i-1 >= 0 and j-1 >= 0:
                A[i-1][j-1] *= -1
    c = 0
    for i in range(M):
        for j in range(N):
            if A[i][j] == -1:
                c += 1
    print c

Submission status: Runtime Error

Solution code:
import numpy as np
N,M=map(int,input().split())

A=np.zeros((N,M))
def re(x,y):
    global A
    try:
        if x>=0 and y>=0:
            if A[x][y]==0:
                A[x][y]=1
            else:
                A[x][y]=0
    except:
        pass
    return A


for i in range(N):
    for j in range(M):
        for X in range(-1,2):
            for Y in range(-1,2):
                re(i+X,j+Y)

print(np.count_nonzero(A))

Submission status: Runtime Error

Solution code:
data = input()
data = data.split(" ")
n = int(data[0])
m = int(data[1])
if n>1 and m>1: print(n*m-2*(n+m)+4)
elif n=1 and m=1: print(1)
else: print(n*m-2)

Submission status: Runtime Error

Solution code:
input_lines = input().split(" ")
n = int(input_lines[0])
m = int(input_lines[1])

if n == 1 and m == 1:
  	return 1
  
if n == 1 or m == 1:
	if n == 1:
		return m - 2
	else:
		return n - 2

return (m-2)*(n-2)

Submission status: Runtime Error

Solution code:
x = int(input().split(" "))
if x[0] == 1 and x[1] == 1:
    count =1
elif x[0] == 1 or x[1] == 1:
    count = max(x[0], x[1])-2
else:
    count = (x[0]-2)*(x[1]-2)
print(count)

Submission status: Runtime Error

Solution code:
a,b=map(int-2,input().split());print(abs(a*b))

Submission status: Runtime Error

Solution code:
print(abs((int(input())-2)*(int(input())-2)))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
M = int(input())

C = 0

for i in range(N:
    for j in range(M):
        c = 0
        for k in range(2):
            for l in range(2):
                if ((i+k <= N-1) and (j+l <= M-1)):
                    c += 1
                if ((i-k >= 0) and (i-l >= 0)):
                    c += 1
        if c % 2 == 1:
            C += 1

print(C)

Submission status: Runtime Error

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

status = [[1]*M]*N

def countCard(j,i):
	count = 0
	left=0
	right=0
	up =0
	down=0

	if j-1 >= 0:
		left = 1

	if j+1 < M:
		right = 1

	if i-1 >= 0:
		up = 1

	if i+1 < N:
		down = 1

	a= left + right + up + down
	if a == 4:
		return 0	#9
	elif a == 3:
		return 1	#6
	elif a == 2:
		if left + right == 0 or up+down==0:
			return 0	#3
		else:
			return 1	#4
	elif a == 1:
		return 1	#2
	elif a == 0:
		return 0

ans = 0

if M >= 3 and N >=3:
	ans = (M-2)*(N-2)
else:
	for i in range(N):
		for j in range(M):
			status[i][j] = countCard(j,i)
			ans += status[i][j]
	ans = (M*N) - ans

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N,M = map(int, input().split())
bord = np.zeros((N, M))

if N < 3 or M < 3:
    for n in range(N):
        for m in range(M):
            if n < 1 and m < 1:
                bord[0:n+2,0:m+2] += 1
            elif n < 1:
                bord[0:n+2,m-1:m+2] += 1
            elif m < 1:
                bord[n-1:n+2,0:m+2] += 1
            else:
                bord[n-1:n+2,m-1:m+2] += 1
    bord = bord % 2

#     print(bord)
    print(int(np.sum(bord)))
else:
    print(N*M - ((N-2)*2+(M-2)*2+4))

Submission status: Runtime Error

Solution code:
N,M=input().split()
N,M=[int(N),int(M)]
#M ga retu j
#N ga gyou i
status = [[1]*M]*N

#0 0 0 0 0 0 0
#print(status)

def countCard(j,i):
	#print("-------------")
	#print("status[{}][{}]={}".format(i,j,status[i][j]))
	count = 0
	left=0
	right=0
	up =0
	down=0

	if j-1 >= 0:
		left = 1

	if j+1 < M:
		right = 1

	if i-1 >= 0:
		up = 1

	if i+1 < N:
		down = 1

	a= left + right + up + down
	#print("left:{},right:{},up:{},down:{}".format(left,right,up,down))
	if a == 4:
		return 0	#9
	elif a == 3:
		return 1	#6
	elif a == 2:
		if left + right == 0 or up+down==0:
			return 0	#3
		else:
			return 1	#4
	elif a == 1:
		return 1	#2
	elif a == 0:
		return 0
	else:
		print('error')
		quit()

ans = 0
for i in range(N):
	for j in range(M):
		status[i][j] = countCard(j,i)
		ans += status[i][j]
		#print("status[{}][{}]={}".format(i,j,status[i][j]))


#print(status)

#for i in range(N):
#	ans += sum(status[i])
ans = (M*N) - ans
print(ans)

Submission status: Runtime Error

Solution code:
# coding:utf-8

in1 = input().split()

in1 = [int(i) for i in in1]

if(in1[0]==1 fand in1[1]==1):
    print("1")
elif(in1[0]==1 or in1[1]==1):
    print((in1[0]-2)*(in1[1]-2)*(-1))
else:
    print((in1[0]-2)*(in1[1]-2))

Submission status: Runtime Error

Solution code:
import numpy as np
N,M = map(int, input().split())
bord = np.zeros((N, M))

for n in range(N):
    for m in range(M):
#         print(n,m)
        if n < 1 and m < 1:
            bord[0:n+2,0:m+2] += 1
        elif n < 1:
            bord[0:n+2,m-1:m+2] += 1
        elif m < 1:
            bord[n-1:n+2,0:m+2] += 1
        else:
            bord[n-1:n+2,m-1:m+2] += 1
#         print(bord)
#         print('-'*10)

# for n in range(N):
#     for m in range(M):
# #         print(n,m)
#         if n < 1 and m < 1 or n == N-1 and m == M-1 or n < 1 and m == M-1 or m < 1 and n == N-1:
#             bord[n,m] = 4
#         elif n < 1 or n == N-1:
#             bord[n,m] = 6
#         elif m < 1 or m == M-1:
#             bord[n,m] = 6
#         else:
#             bord[n,m] = 1
    
bord = bord % 2

# print(bord)
print(int(np.sum(bord)))

Submission status: Runtime Error

Solution code:
IN=input().split(' ')
N=IN[0]
M=IN[1]
if (N==1 and M==1)or (N!=1 and M!=1):
    print((N-2)*(M-2))
else:
    print(N*M-2)

Submission status: Runtime Error

Solution code:
N,M=input().split()
N,M=[int(N),int(M)]
#M ga retu i
#N ga gyou j
status = [[1]*M]*N

#print(status)

def countCard(j,i):
	#print("-------------")
	#print("status[{}][{}]={}".format(i,j,status[i][j]))
	count = 0
	left=0
	right=0
	up =0
	down=0
	tmp = j-1
	if tmp >= 0:
		left = 1
	tmp = j+1
	if tmp < M:
		right = 1
	tmp=i-1
	if tmp >= 0:
		up = 1
	tmp=i+1
	if tmp < N:
		down = 1
	a= left + right + up + down
	#print("left:{},right:{},up:{},down:{}".format(left,right,up,down))
	if a == 4:
		return 0	#9
	elif a == 3:
		return 1	#6
	elif a == 2:
		if left + right == 0 or up+down==0:
			return 0	#3
		else:
			return 1	#4
	elif a == 1:
		return 1	#2
	elif a == 0:
		return 0
	else:
		print('error')
		quit()


for i in range(M):
	for j in range(N):
		status[j][i] = countCard(j,i)
		#print("status[{}][{}] = {}".format(i,j,status[i][j]))


#print(status)
ans = 0
for i in range(N):
	ans += sum(status[i])
print(ans)

Submission status: Runtime Error

Solution code:
L,M=map(int,input().split())
import numpy as np
a=np.zeros((L,M))
count=0
for i in range(L):
    for j in range(M):
        if L>=3 and M>=3:
            if i>=1 and i<=L-2 and j>=1 and j<=M-2:
                count+=1
                continue
        syuui=0
        a=[[i-1,j-1],[i-1,j],[i-1,j+1],[i,j-1],[i,j],[i,j+1],[i+1,j-1],[i+1,j],[i+1,j+1]]
        for k in a:
            if 0<=k[0] and k[0]<L and k[1]>=0 and k[1]<M:
                syuui+=1
        if syuui%2==1:
            count+=1
print(count)

Submission status: Runtime Error

Solution code:
L,M=map(int,input().split())
import numpy as np
a=np.zeros((L,M))
count=0
for i in range(L):
    for j in range(M):
        syuui=0
        a=[[i-1,j-1],[i-1,j],[i-1,j+1],[i,j-1],[i,j],[i,j+1],[i+1,j-1],[i+1,j],[i+1,j+1]]
        for k in a:
            if 0<=k[0] and k[0]<L and k[1]>=0 and k[1]<M:
                syuui+=1
        if syuui%2==1:
            count+=1
print(count)

Submission status: Runtime Error

Solution code:
def get_z(x, y):
    global N
    return (y+1)*(N+2) + (x+1)

N, M = map(int, input().split())
table = [-1] * (N+2) + [[1, -1][i in [0, N+1]] for i in range(N+2)] * M + [-1] * (N+2)
for y in range(M):
    for x in range(N):
        z = get_z(x, y)
        for t in [(z-(N+3)), (z-(N+2)), (z-(N+1)), z-1, z, z+1, z+N+1, z+N+2, z+N+3]:
            table[t] = table[t] ^ 1
print(sum(1 * (t==0) for t in table))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    import numpy as np

    N, M = list(map(int, input().split()))
    s = np.zeros([N, M], dtype=int)

    for i in range(N):
        for j in range(M):
            for dx in range(-1, 2):
                for dy in range(-1, 2):
                    if (0 <= i + dy < N) and (0 <= j + dx < M):
                        if s[i][j] == 0:
                            s[i][j] = 1
                        else:
                            s[i][j] = 0

    print(np.sum(s))