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:
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:
# -*- coding: utf-8 -*-
#ARC091C
tmp = input().split()
n,m = list(map(lambda a: int(a), tmp))

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

Submission status: Wrong Answer

Solution code:
# 2019/07/23

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

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

Submission status: Wrong Answer

Solution code:
# 2019/07/23

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

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

Submission status: Wrong Answer

Solution code:
# 書けばわかる 裏になるのは奇数回訪れる場所
n, w = map(int, input().split())
print(n*w-(2*n+2*w-4))

Submission status: Wrong Answer

Solution code:
# ARC091C - Flip,Flip, and Flip......
def main():
    n, m = sorted(list(map(int, input().rstrip().split())))
    if n == 1:
        print(m - 2)
    elif n == 2:
        print(0)
    else:
        print((n - 2) * (m - 2))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

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 = (int(i) for i in input().split())
if n == 1:
    if m == 1:
        print(1)
    elif m>1:
        print(m-2)
#elif n ==2:
#    print(0)
else:
    #print(n*m-(2*m+(n-2)*2))
    print((n-2)*(m-2))

Submission status: Wrong Answer

Solution code:
n,m = (int(i) for i in input().split())
if n == 1:
    if m == 1:
        print(1)
    else:
        print(m-2)
#elif n ==2:
#    print(0)
else:
    #print(n*m-(2*m+(n-2)*2))
    print((n-2)*(m-2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
if 1 == H == W:
	print(0)
	exit()

if 1 == H and not 1 == W:
	print(W - 2)
	exit()

if 1 == W and not 1 == H:
	print(H - 2)
	exit()

print((H - 2) * (W - 2))

"""
stage = [[0 for _ in range(W)] for _ in range(H)]
ds = ((0, 0), (1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1))

def setv(p, v):
	global stage
	stage[p[1]][p[0]] = v

def getv(p):
	return stage[p[1]][p[0]]

def move(p, d):
	r = (p[0] + d[0], p[1] + d[1])
	if not (0 <= r[0] < W) or not (0 <= r[1] < H):
		return None
	return r

for h in range(H):
	for w in range(W):
		for d in ds:
			nextp = move((w, h), d)
			if not nextp:
				continue
			setv(nextp, (getv(nextp) + 1) % 2)
			#setv(nextp, (getv(nextp) + 1))

for h in range(H):
	print(*stage[h], sep="")
print()
"""

Submission status: Wrong Answer

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

"""
stage = [[0 for _ in range(W)] for _ in range(H)]
ds = ((0, 0), (1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1))

def setv(p, v):
	global stage
	stage[p[1]][p[0]] = v

def getv(p):
	return stage[p[1]][p[0]]

def move(p, d):
	r = (p[0] + d[0], p[1] + d[1])
	if not (0 <= r[0] < W) or not (0 <= r[1] < H):
		return None
	return r

for h in range(H):
	for w in range(W):
		for d in ds:
			nextp = move((w, h), d)
			if not nextp:
				continue
			setv(nextp, (getv(nextp) + 1) % 2)
			#setv(nextp, (getv(nextp) + 1))

for h in range(H):
	print(*stage[h], sep="")
print()
"""

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

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

if N == M == 1:
    ans == 1
elif min(N, M) == 1:
    ans = max(N, M) - 2
else:
    ans = N * M - (N + M) * 2 + 4

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: 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:
  print(1)
  
elif N == 1 or 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:
  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:
    temp = (n * m) - 2
    if temp < 0:
        print(0)
        exit()
    print(temp)
elif n == 2 or 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 and M == 1:
    print(1)
if N == 1:
    print(M-N*2)
elif M == 1:
    print(N-M*2)
else:
    print(N*M-2*M-2*(N-2))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
if a==1 and b==1:
  print(1)
elif a==1 or b==1:
  print(max(a,b)-2)
else:
  print(a+a+b+b-8)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, m = list(map(int, input().split()))
if n == 1 and m == 1:
    print(1)
else:
    a = min(2, n)
    b = max(0, n-2)
    c = min(2, m)
    d = max(0, m-2)

    print(b*d)

Submission status: Wrong Answer

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

if N == 2 or M == 2:
    print(0)
    exit()

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

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

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

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

Submission status: Wrong Answer

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

if N == 2 or M == 2:
    print(0)
    exit()

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

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

Submission status: Wrong Answer

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

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

if N == 2:
    print(0)
    exit()

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((m-2)*(n-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(max(0,N*M-(2*N+2*M-4)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N, M = map(int, input().split())
    if (N > M):
        N, M = M, N
    if (N == 1):
        print (max(0, M - 2))
        exit(0)
    result = (N - 2) * (M - 2)
    print (result)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!


from collections import deque
lines = input().split(' ')
m = int(lines[0])
n = int(lines[1])

m = 314
n = 1592

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!


from collections import deque
lines = input().split(' ')
m = int(lines[0])
n = int(lines[1])

from collections import deque

masume = {}
casesingle = [3, 3, 2]
casemultiple = [9, 6, 4]
def cal(m_, n_, m, n):
    if m-1 >  m_ > 0 and n-1 > n_ > 0 :
        return 0
    else:
        if m == 1 or n == 1:
            if sum([
                m_ == 0,
                n_ == 0,
                m_ == m-1,
                n_ == n-1,
            ]) == 2:
                return 1
            else:
                return 2
        else:
            sum_ = sum([
                m_ == 0,
                m_ == m-1,
                n_ == 0,
                n_ == n-1,
            ])
            if sum_ == 2:
                return 2
            else:
                return 1

for m_ in range(m):
    for n_ in range(n):
        if m == 1 or n == 1:
            choices = casesingle[cal(m_, n_, m, n)]
        elif m == 1 and n == 1:
            choices = 1
        else:
            choices = casemultiple[cal(m_, n_, m, n)]
        masume[(m_, n_ )] = choices

count = 0
count1 = 0
for key in masume:
    if masume[key] % 2 == 1:
        count += 1
    else:
        count1 += 1
print(count)

Submission status: Wrong Answer

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

if N == 1 and M ==1:
  print(0)
elif 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())

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

if M > N:
    tmp = N
    M = N
    N = tmp

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

Submission status: Wrong Answer

Solution code:
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

(N, M) = reads()

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

print(ans)

Submission status: Wrong Answer

Solution code:
MN=list(map(int, input().split()))
if MN[0] <= 2 or MN[1] <= 2:
  c = 0
else:
  c = (MN[0] - 2)*(MN[1] - 2)
print(c)

Submission status: Wrong Answer

Solution code:
print(-1)

Submission status: Wrong Answer

Solution code:
def num_remainder(n, rem, div):
    if rem == 0:
        rem = div
    a = n+div-rem
    return a // div

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

ans = 0

for i in range(k+1, n+1):
    for j in range(k, i):
        ans += num_remainder(n, j, i)

print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
    N, K = map(int, input().split())

    res = 0
    for b in range(K+1, N+1):
        res += b-K
        res += (N//b - 1) * (b-K)
        res += (N%b)-K+1 if N%b >= K else 0
    if K == 0:
        res -= N
    print(res)

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
a = str(input()).split()
n = int(a[0])
m = int(a[1])
k = []
l = []
answer = 0 

for i in range(0,m+2):
    l.append(1)
for i in range(0,n+2):
    k.append(l)

for i in range(1,n+1):
    for j in range(1,m+1):
        k[i-1][j-1] = -k[i-1][j-1] 
        k[i-1][j] = -k[i-1][j]
        k[i-1][j+1] = -k[i-1][j+1]
        k[i][j-1] = -k[i][j-1]
        k[i][j] = -k[i][j]
        k[i][j+1] = -k[i][j+1]
        k[i+1][j-1] = -k[i+1][j-1]
        k[i+1][j] = -k[i+1][j]
        k[i+1][j+1] = -k[i+1][j+1]


for i in range(1,n+1):
    for j in range(1,m+1):
        if k[i][j] < 0:
            answer += 1
            
print(answer)

Submission status: Wrong Answer

Solution code:
n, m = (int(x) for x in input().split())
if n > m:
    n, m = m, n
if n == 1:
    if m == 1:
        print(0)
    else:
        print(m-2)
else:
    print(n*m-2*m-2*n+4)

Submission status: Wrong Answer

Solution code:
def solve():
    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))


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    if N == 1:
        print(N-2)
        return

    if M == 1:
        print(M-2)
        return

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


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if (HW[0] == 1 or HW[1] == 1):
	count = HW[0] * HW[1] - 2
else:
	count = (HW[0] - 2) * (HW[1] - 2)

print(max(0, count))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
num = map(int,raw_input().split())
n = num[0]
m = num[1]

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
row = [1 for i in range(m)]
field = [row for i in range(n)]

dc = [-1, 0, 1, -1, 0, 1, -1, 0, 1]
dr = [-1, -1, -1, 0, 0, 0, 1, 1, 1]

for i in range(n):
    for j in range(m):
        for k in range(9):
            r = i + dr[k]
            c = j + dc[k]

            if r < 0 or r > n-1 or c < 0 or c > m-1:
                continue

            field[r][c] *= -1

ans = 0
for x in field:
    for y in x:
        if y == -1:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = list(map(int, input().split()))
result = 0
pos = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 0), (0, 1), (1, -1), (1, 0), (1, 1)]
for i in range(N):
    for j in range(M):
        num = 0
        for p in pos:
            i_dest = i + p[0]
            j_dest = j + p[1]
            if 0 <= i_dest < N and 0 <= j_dest < M:
                num += 1
        if num % 2 != 0:
            result += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
def dxdy(n, m, x, y):
    dx = [0,0,1,1,1,-1,-1,-1]
    dy = [1,-1,0,1,-1,0,1,-1]

    cnt = 1
    for i in range(8):
        if 0<=x+dx[i] and x+dx[i]<n and 0<=y+dy[i] and y+dy[i]<m:
            cnt += 1

    return cnt

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

    ans = 0

    for i in range(n):
        for j in range(m):
            if dxdy(n, m, i, j)%2 == 1:
                ans += 1

    return ans

print(solve())

Submission status: Time Limit Exceeded

Solution code:
dx = [-1, -1, -1, 0, 1, 1, 1, 0]
dy = [1, 0, -1, -1, -1, 0, 1, 1]

# 0 裏 1 表
n, m = map(int, input().split())
count = 0
if n == 1 or m == 1:
    for i in range(n):
        for j in range(m):
            xy_count = 0
            for x, y in zip(dx, dy):
                if i + y == -1 or i + y == n or j + x == -1 or j + x == m:
                    continue
                # lis[i + y][j + x] = not lis[i + y][j + x]
                xy_count += 1
            if xy_count % 2 == 0:
                count += 1
    print(count)
else:
    print(n * m - (2 * n + 2 * m - 4))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# author:  Taichicchi
# created: 28.09.2020 23:24:54

import sys

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m = map(int, input().split())
if n == 1 and m == 1:
    print(1)
    sys.exit(0)
if n == 1:
    print(m - 2)
    sys.exit(0)
if m == 1:
    print(n - 2)
    sys.exit(0)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, M = 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:
    if M == 1:
        print(1)
    else:
        print(M - 2)
    exit()
elif M == 1:
    print(N - 2)
    exit()
elif N == 2 or M == 2:
    print(0)
    exit()
else:
    print((N - 2) * (M - 2))

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
if min(a,b)>=3:
    print( (a-2)*(b-2))
    exit()
if a>b: a,b=b,a
if a==1 and b>=3:
    print(b-2)
if a==2 and b>=3:
    print(0)


if [a,b]==[1,1]:
    print(1)
if [a,b]==[1,2]:
    print(0)
if [a,b]==[2,2]:
    print(0)

Submission status: Accepted

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

if n>=3 and m>=3:
  a=n*m
  b=n*2+m*2-4
  ans=a-b
elif n==1 and m==1:
  ans=1
elif n==1 or m==1:
  a=n*m
  b=2
  ans=a-b
elif n==2 or m==2:
  ans=0
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)

N,M = mint()
if N==M==1:
    print(1)
else:
    print(abs(N-2)*abs(M-2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#a = int(input())
	h, w = tin()
	#s = input()
	if h==1 and w==1:
		return 1
	elif h==1 or w == 1:
		return max(h,w)-2
	else:
		return h*w + 4 - 2*h -2*w
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

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

if N == 1 and M == 1:
    print(1)
else:
    print(cm*cn)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#29 C - Flip,Flip, and Flip......
N,M = map(int,input().split())
N,M = min(N,M), max(N,M)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
H,W=list(map(int,input().split()))
if H==1 and W==1:
   print(1)
   exit()
if H==1 or W==1:
   print(H*W-2)
   exit()
futi=(H+W)*2-4
print(H*W-futi)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

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