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 = (int(i) for i in input().split())

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

elif N == 2:
    print(0)

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

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a = n - 2 if n > 2 else 0
b = m - 2 if m > 2 else 0
counter =  a * b

if counter == 0:
    if n == 1 and m == 1:
        counter = 0
    elif n == 1:
        counter = m - 2
    else:
        counter = n - 2

print(counter)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

tiles = [[True for i in range(M + 2)] for j in range(N + 2)]
print(tiles)
for i in range(1, N + 1):
    for j in range(1, M + 1):
        tiles[i - 1][j - 1] = not (tiles[i - 1][j - 1])
        tiles[i - 1][j] = not (tiles[i - 1][j])
        tiles[i - 1][j + 1] = not (tiles[i - 1][j + 1])
        tiles[i][j - 1] = not (tiles[i][j - 1])
        tiles[i][j] = not (tiles[i][j])
        tiles[i][j + 1] = not (tiles[i][j + 1])
        tiles[i + 1][j - 1] = not (tiles[i + 1][j - 1])
        tiles[i + 1][j] = not (tiles[i + 1][j])
        tiles[i + 1][j + 1] = not (tiles[i + 1][j + 1])

count = 0

for i in range(1, N + 1):
    for j in range(1, M + 1):
        if not tiles[i][j]:
            count = count + 1
print(count)

Submission status: Wrong Answer

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

tiles = [[True for i in range(M + 2)] for j in range(N + 2)]
print(tiles)
for i in range(1, N + 1):
    for j in range(1, M + 1):
        tiles[i - 1][j - 1] = not (tiles[i - 1][j - 1])
        tiles[i - 1][j] = not (tiles[i - 1][j])
        tiles[i - 1][j + 1] = not (tiles[i - 1][j + 1])
        tiles[i][j - 1] = not (tiles[i][j - 1])
        tiles[i][j] = not (tiles[i][j])
        tiles[i][j + 1] = not (tiles[i][j + 1])
        tiles[i + 1][j - 1] = not (tiles[i + 1][j - 1])
        tiles[i + 1][j] = not (tiles[i + 1][j])
        tiles[i + 1][j + 1] = not (tiles[i + 1][j + 1])

count = 0

for i in range(1, N + 1):
    for j in range(1, M + 1):
        print(tiles[i][j])
        if not tiles[i][j]:
            count = count + 1
print(count)

Submission status: Wrong Answer

Solution code:
n = raw_input()
n= n.split()
N = int(n[0])
M = int(n[1])

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

Submission status: Wrong Answer

Solution code:
print(eval('~-~-'+input().replace(' ','*~-~-')))

Submission status: Wrong Answer

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

if N > 1 and M > 1:
    front = (N-1)*2 + (M-1)*2
    print(cards - front)
else:
    print(max(N, M) - 2)

Submission status: Wrong Answer

Solution code:
n, m = sorted([int(i) for i in input().split()])
a = None
if n == 1 and m == 1:
    a = 1
elif n == 1:
    a = m - 2
else:
    a = n * m - 4
print(a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
lis = list(map(int, input().split()))
n = lis[0]
m = lis[1]
count = 0

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

Submission status: Wrong Answer

Solution code:
lis = list(map(int, input().split()))
n = lis[0]
m = lis[1]
count = 0

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

Submission status: Wrong Answer

Solution code:
lis = list(map(int, input().split()))
n = lis[0]
m = lis[1]
count = 0

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
rows, columns = map(int, input().split(' '))

if rows == 1:
    print(columns - 2)
    exit()
if columns == 1:
    print(rows - 2)
    exit()

print(rows * columns - 2 * rows - 2 * columns + 4)

Submission status: Wrong Answer

Solution code:
import numpy
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 M==2:
    print(0)
else:
    print((N-2)*(M-2))

Submission status: Wrong Answer

Solution code:
lis = list(map(int, input().split()))
n = lis[0]
m = lis[1]
count = 0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
rows, columns = map(int, input().split(' '))

result = 0

if rows == 1:
    print(columns - 2)
    exit()
if columns == 1:
    print(rows - 2)
    exit()

for row in range(int(rows / 2)):
    for column in range(int(columns / 2)):
        target_time = 0

        inc_column = column + 1 < columns
        dec_column = 0 <= column - 1
        inc_row = row + 1 < rows
        dec_row = 0 <= row - 1

        if inc_column:
            if inc_row:
                target_time += 1
            if dec_row:
                target_time += 1
        if dec_column:
            if inc_row:
                target_time += 1
            if dec_row:
                target_time += 1

        if dec_column:
            target_time += 1
        if inc_column:
            target_time += 1
        if inc_row:
            target_time += 1
        if dec_row:
            target_time += 1

        if target_time % 2 == 0:
            result += 1

            if columns - 1 != 2 * column:
                if rows - 1 != 2 * row:
                    result += 1
            if columns - 1 != 2 * column:
                result += 1
            if rows - 1 != 2 * row:
                result += 1

print(result)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
n,m=map(int,input().split())
if n==m==1:
    print(1)
    exit()
ans=0
ans+=max((n-2),(1 if m>=3 else 0))*max((m-2),(1 if n>=3 else 0))
if (n==2 or m==2) and n!=m and n+m>3:
    ans+=3

print(0 if n==2 and m==4 or n==4 and m==2 else ans)

Submission status: Wrong Answer

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

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

elif N == 2 or M == 2:
    print(0)
    
else:
    print(N*M - ((N-2)*2+(M-2)*2+4))

Submission status: Wrong Answer

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

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

elif N == 2 or M == 2:
    print(0)

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
n,m=map(int,input().split())
if n==m==1:
    print(1)
    exit()
ans=0
ans+=max((n-2),(1 if m>=3 else 0))*max((m-2),(1 if n>=3 else 0))
if (n==2 or m==2) and n!=m and n+m>3:
    ans+=3
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
n,m=map(int,input().split())
if n==m==1:
    print(1)
    exit()
ans=0
ans+=max((n-2),(1 if m>=3 else 0))*max((m-2),(1 if n>=3 else 0))
if (n==2 or m==2) and n!=m:
    ans+=3
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
n,m=map(int,input().split())
if n==m==1:
    print(0)
    exit()
ans=0
ans+=max((n-2),(1 if m>=3 else 0))*max((m-2),(1 if n>=3 else 0))
if (n==2 or m==2) and n!=m:
    ans+=3
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
n,m=map(int,input().split())
if n==m==1:
    print(0)
    exit()
ans=0
ans+=max((n-2),(1 if m>=3 else 0))*max((m-2),(1 if n>=3 else 0))
print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N, M = list(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:
L,M=map(int,input().split())
count=0
if L==1 or M==1:
    print(L+M-3)
if L==2 or M==2:
    print(0)
if L>=3 and M>=3:
    print((L-2)*(M-2))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split(" "))
field = []
for i in range(N+2):
    field.append([1 for i in range(M+2)])
for i in range(N):
    for j in range(M):
        field[i+1][j+1] = field[i+1][j+1]*-1
        field[i+1+1][j+1] = field[i+1+1][j+1]*-1
        field[i+1+1][j+1-1] = field[i+1+1][j+1-1]*-1
        field[i+1+1][j+1+1] = field[i+1+1][j+1+1]*-1
        field[i+1-1][j+1] = field[i+1-1][j+1]*-1
        field[i+1-1][j+1+1] = field[i+1-1][j+1+1]*-1
        field[i+1-1][j+1-1] = field[i+1-1][j+1-1]*-1
        field[i+1][j+1+1] = field[i+1][j+1+1]*-1
        field[i+1][j+1-1] = field[i+1][j+1-1]*-1

cou = 0
for i in range(N):
    cou = cou + field[i+1][1:M].count(-1)
print(cou)

Submission status: Wrong Answer

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

n,m = input().split()

N = int(n)
M = int(m)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def main():
    N,M = list(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*M - (2*(N+M)-4))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

if n==1 and m==1:
    ans=1
if n==2 and m==1:
    ans=0
if m==2:
    ans=0


print(ans)

Submission status: Wrong Answer

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

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

if n==1 and m==1:
    ans=1
if n==2 and m==1:
    ans=0
if n==1 and m==2:
    ans=0
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

    if min(N, M) == 1:
        i = max(N, M)
        if i < 3:
            back = 0
        else:
            back = i - 2
    elif N == 2 or M == 2:
        back = 0
    else:
        back = N * M - ((N + M) * 2 - 4)
    print(back)

main()

Submission status: Wrong Answer

Solution code:
#N,M = map(int,input().split(" "))
N=2
M=4
field = []
hani = [0 for i in range(9)]
power = 0
for i in range(N+2):
    field.append([1 for i in range(M+2)])
for i in range(N):
    for j in range(M):
        field[i+1][j+1] = field[i+1][j+1]*-1
        field[i+1+1][j+1] = field[i+1+1][j+1]*-1
        field[i+1+1][j+1-1] = field[i+1+1][j+1-1]*-1
        field[i+1+1][j+1+1] = field[i+1+1][j+1+1]*-1
        field[i+1-1][j+1] = field[i+1-1][j+1]*-1
        field[i+1-1][j+1+1] = field[i+1-1][j+1+1]*-1
        field[i+1-1][j+1-1] = field[i+1-1][j+1-1]*-1
        field[i+1][j+1+1] = field[i+1][j+1+1]*-1
        field[i+1][j+1-1] = field[i+1][j+1-1]*-1

cou = 0
for i in range(N):
    cou = cou + field[i+1][1:M].count(-1)
print(cou)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

n,m = input().split()

N = int(n)
M = int(m)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A,B = map(int,input().split(" "))
ans = 0
if A >=3 and B >= 3:
    ans = A*B-(A*2 + B*2)+4
    print(ans)

if A == 1 and B!=1:
    print(B-2)
elif B == 1 and A != 1:
    print(A-2)
elif A == 1 and B ==1:
    print(1)
elif A == 2 and B ==3:
    print(0)
elif A == 3 and B ==2:
    print(0)
elif A == 2 and B ==2:
    print(0)

Submission status: Wrong Answer

Solution code:
#coding : utf-8

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

masu = []
_list = []
for n in range(N):
    _list = [1 for i in range(M)]
    masu.append(_list)


#print(masu)

def masu_reverse(masu, n, m):
    for s in range(-1,2):
        for x in range(-1,2):
            if n+s <= N-1 and n+s>= 0 and m+x < M-1 and m+x>=0: 
                masu[n+s][m+x] = masu[n+s][m+x]*-1

for i in range(N):
    for j in range(M):
        masu_reverse(masu,i,j)


ans = 0
for e in range(N):
    for f in range(M):
        if masu[e][f] == -1:
            ans += 1

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    n, m = map(int, input().split())

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n,m = na()

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
A,B = map(int,input().split(" "))
ans = 0
if A >=3 and B >= 3:
    ans = A*B-(A*2 + B*2)+4
    print(ans)

if A == 1 and B!=1:
    print(B-2)
elif B == 1 and A != 1:
    print(A-2)
elif A == 1 and B ==1:
    print(0)
elif A == 2 and B ==3:
    print(0)
elif A == 3 and B ==2:
    print(0)
elif A == 2 and B ==2:
    print(0)

Submission status: Wrong Answer

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

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

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

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:
a = input().split()
print(int(a[0]) * int(a[1]) -(int(a[0])*2 + int(a[1])*2 - 4))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
A,B = map(int,input().split(" "))
ans = 0
if A >=3 and B >= 3:
    ans = A*B-(A*2 + B*2)+4
    print(ans)

if A == 1:
    print(B-2)
elif B == 1:
    print(A-2)
elif A == 1 and B ==1:
    print(0)
elif A == 2 and B ==3:
    print(0)
elif A == 3 and B ==2:
    print(0)
elif A == 2 and B ==2:
    print(0)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

if N == 1 or M == 1:
	print (N+M-3);

elif N == 2 or M == 2:
	print (0);
else:
	print ((N-2)*(M-2))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def main():
    N, M = list(map(int, input().split()))
    if 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: Wrong Answer

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

if (x[0]==1 or x[1]==1):
    print(2)    
    quit()

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

quit()

Submission status: Wrong Answer

Solution code:
N,M = [int(i) for i in input().split()]
print(N*M-2*N-2*M+4)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, M = (int(i) for i in input().split())
if 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: Wrong Answer

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

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

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

Submission status: Wrong Answer

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
print(a-s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Time Limit Exceeded

Solution code:
a,b=map(int, input().split())
array=[]
for i in range(a+2):
  array2=[]
  for j in range(b+2):
    array2.append(True)
  array.append(array2)
for i in range(1,a+1):
  for j in range(1,b+1):
    meguru=[[0,0],[0,1],[1,0],[1,1],[0,-1],[-1,0],[-1,1],[1,-1],[-1,-1]]
    for k in meguru:
      if array[i+k[0]][j+k[1]]==True:
        array[i+k[0]][j+k[1]]=False
      else:
        array[i+k[0]][j+k[1]]=True
counter=0
for i in range(1,a+1):
  for j in range(1,b+1):
    if array[i][j]==False:
      counter+=1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
A = []
A.append([0 for _ in range(m+2)])
for _ in range(n):
    A.append([0] + [1 for _ in range(m)] + [0])
A.append([0 for _ in range(m+2)])

for i in range(1, n+1):
    for j in range(1, m+1):
        A[i][j-1] *= -1
        A[i][j] *= -1
        A[i][j+1] *= -1
        A[i+1][j-1] *= -1
        A[i+1][j] *= -1
        A[i+1][j+1] *= -1
        A[i-1][j-1] *= -1
        A[i-1][j] *= -1
        A[i-1][j+1] *= -1
        
import itertools
print(list(itertools.chain.from_iterable(A)).count(-1))

Submission status: Time Limit Exceeded

Solution code:
url = "https://atcoder.jp/contests/abc090/tasks/arc091_a"
import copy
def main():
    tate, yoko = list(map(int, input().split()))
    count = 0
    if tate == 1 and yoko == 1:
        print("1")
        exit()
    elif tate == 1:
        print(yoko - 2)
        exit()
    elif yoko == 1:
        print(tate - 2)
        exit()
    for t in range(1, tate + 1):
        if t == 1 or t == tate:
            count += 0
        else:
            count += yoko - 2
    print(count)




if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
url = "https://atcoder.jp/contests/abc090/tasks/arc091_a"
import copy
def main():
    tate, yoko = list(map(int, input().split()))
    count = 0
    for t in range(1, tate + 1):

        for y in range(1, yoko + 1):
            arround = 0
            if tate == 1 and yoko == 1:
                arround += 1
            elif (t == 1 and t == tate) or (y == 1 and y == yoko):
                if (1 < t < tate) or (1 < y < yoko):
                    arround += 3
                else:
                    arround += 2
            elif (t == 1 or t == tate) and (y == 1 or y == yoko):
                arround += 4
            elif (t == 1 or t == tate) or (y == 1 or y == yoko):
                arround += 6
            else:
                arround += 9
            if arround % 2 != 0:
                count += 1
    print(count)




if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

N,M = list(map(int, input().rstrip().split()))
#-----

delta = [(-1,-1) , (0,-1), (1,-1),
         (-1, 0) , (0, 0), (1, 0),
         (-1, 1) , (0, 1), (1, 1)]


ans=0
for y in range(N):
    for x in range(M):
        
        check_cnt=0
        for d in delta:
            check_x = x + d[0]
            check_y = y + d[1]
            
            if 0 <= check_x <= (M-1) and 0 <= check_y <= (N-1):
                check_cnt += 1
        
        if check_cnt % 2 == 1:
            ans += 1

print(ans)