Problem:


Score : 300 points

Problem Statement

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

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

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

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

Constraints

1 \leq N,M \leq 10^9

All input values are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

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

Sample Input 1

2 2

Sample Output 1

0

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

Sample Input 2

1 7

Sample Output 2

5

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

Sample Input 3

314 1592

Sample Output 3

496080



Sample input:
2 2


Sample output:
0

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

s=min(N,M)
l=max(N,M)

ans=None

if s==1:
    if l>=2: ans=l-2
    else: ans=1

elif s==2: ans=0
else:
    ans=(s-2)*(l-2)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = raw_input().split(' ');
n = int(n);
m = int(m);
if ((n == 1) & (m == 1)):
    print 1;
elif (n == 1):
    print m - 2;
elif (m == 1):
    print n - 2;
else :
    print n * m - 2 * (n - 1) - 2 * (m - 1);

Submission status: Accepted

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

Submission status: Accepted

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

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

    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: Accepted

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

if N == 1:
    N = 3


if M == 1:
    M = 3

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

Submission status: Accepted

Solution code:
import sys
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [long(input_raw[0]), long(input_raw[1])]
    if N == 1 and M == 1:
        print 1
    elif N == 1:
        print M - 2
    elif M == 1:
        print N - 2
    else:
        print N * M - ((((M - 1) + (N - 1)) * 2))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import numpy


def main():
    n, m = map(int, input().split())
    if n < m:
        n, m = m, n

    if m == 1 and n == 1:
        return 1

    if m == 1:
        return n - 2

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


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

Submission status: Accepted

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

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

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

if M == 1:
    print(N - 2)
    sys.exit()
print(max((N - 2), 0) * max((M - 2), 0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
x,y=[int(i) for i in input().split()]

if x==1:
    if y == 1:
        print(1)
    else:
        print(y-2)
elif y==1:
    print(x-2)
else:
    print((x-2)*(y-2))

Submission status: Accepted

Solution code:
l = input().split(" ")
W = int(l[0])
H = int(l[1])
if W == 1 and H == 1:
  print(1)
elif W == 1 or H == 1:
  print(W * H - 2)
else:
  print(W * H - 2 * (W + H - 2))

Submission status: Accepted

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[n,m]=i2()
a=1
if n>2:
 a*=n-2
if m>2:
 a*=m-2
if n==2 or m==2:
  a=0
print(a)

Submission status: Accepted

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

ans =0
n1 =0
m1 = 0

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

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

ans = n1*m1


print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
def a(nm):
    if nm == 1:
        return 1
    else:
        return nm - 2
n2, m2 = a(n), a(m)
print(n2*m2)

Submission status: Accepted

Solution code:
x, y = map(int, raw_input().split())
if x == 1:
    if y == 1:
        print 1
    else:
        print y-2
elif y == 1:
    print x-2
else:
    print x*y-2*x-2*(y-2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

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

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

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

solve()

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 * n - 2 * n - 2 * m + 4)

Submission status: Accepted

Solution code:

def calc0(N, M):
    cell = [[0 for i in range(M)] for j in range(N)]
    for i in range(M):
        for j in range(N):
            for y in range(-1, 2):
                for x in range(-1, 2):
                    xx = i + x
                    yy = j + y
                    if 0 <= xx < M and 0 <= yy < N:
                        cell[yy][xx] ^= 1
    r = 0
    for i in range(M):
        for j in range(N):
            if cell[j][i]:
                r += 1
    return r
    
def calc(N, M):
    if N == 1 and M == 1:
        return 1
    if N >= 2 and M >= 2:
        return (N - 2) * (M - 2)
    if N == 1:
        return M - 2
    return N - 2

N, M = [int(_) for _ in input().split()]

print(calc(N, M))

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string

H, W = map(int, input().split())
if H > W:
    H, W = W, H
ans = None
if H == 1:
    if W == 1:
        ans = 1
    else:
        ans = W - 2
elif H == 2:
    ans = 0
else:
    ans = (H - 2) * (W - 2)
print(ans)

Submission status: Accepted

Solution code:
import sys
import random

def rd():
        return sys.stdin.readline().rstrip()

def rdi():
        return [ int(x) for x in rd().split() ]

N, M = rdi()

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
if N == 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:
def solve(n, m):
    if n == 2 or m == 2:
        return 0
    if min(n, m) == 1:
        if max(n, m) == 1:
            return 1
        else:
            return n * m - 2
    return n * m - 2 * (n + m) + 4


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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,m = LI()
    if n == 1 and m == 1:
        return 1

    if n == 1:
        return m - 2
    if m == 1:
        return n - 2

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


print(main())

Submission status: Runtime Error

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

aa = [[1]*(m + 2) for i in range(n+2)]

for i in range(1, n+1):
  for j in range(1, m+1):
    aa[i][j-1] *= -1
    aa[i][j] *= -1
    aa[i][j+1] *= -1
    aa[i-1][j-1] *= -1
    aa[i-1][j] *= -1
    aa[i-1][j+1] *= -1
    aa[i+1][j-1] *= -1
    aa[i+1][j] *= -1
    aa[i+1][j+1] *= -1
aa = aa[1:-1]
bb = [b[1:-1] for b in aa]
cc = [x  for y in bb for x in y]
ans = cc.count(-1)

print(ans)

Submission status: Runtime Error

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

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

if n>=3 and m>=3:
  a=n*m
  b=n*2+m*2-
  ans=a-b
elif n==1 and b==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: Runtime Error

Solution code:
n,m=int(input())

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

Submission status: Runtime Error

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

Solution code:
if N > 1 and M > 1:
    four = 4
    six = (N - 2) * 2 + (M - 2) * 2
    nine = N * M - four - six
    print(nine)
else:
    two = 2
    three = N * M - two
    print(three)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

S = s()
if len(S)==26:
    print(-1)
    sys.exit()

alpha=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

for i in alpha:
    if i not in S:
        print(S+ans)
        sys.exit()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy
 
## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))
 
N,M=map(int, input().split())

if N==1 and M==1:
    print(0)
    sys.exit()

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

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

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

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

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

oo

Submission status: Runtime Error

Solution code:
# マジで納得がいかねぇので01がなんのケースなのかわざわざ調べてやる

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

if n == 1 or m == 1:  # どうせこれだろ
    print(f"kasu")
    print(1 / 0)

Submission status: Runtime Error

Solution code:
def card(n,m):
    try:
        if n >= 0 and n < N and m >= 0 and m < M:
            if a[n][m] == 1:
                a[n][m] = 0
            else:
                a[n][m] = 1
    except:
        None

count = 0
N, M = map(int,input().split())
a = [[0]*N for i in range(M)]

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

la = [0] * (m+2)
li = [0] + [1]*m + [0]

lall = [la]
for i in range(n):
    lall.append(li)
lall.append(la)

# print(lall)
lcnt = [[0]*(m+2)]
for i in range(n+1):
    lcnt.append([0]*(m+2))
#nprint("lcnt =", lcnt)
 
for i in range(1, n+1):
    for j in range(1, m+1):
#        if lall[i-1][j-1:j+2] == [1,1,1] and lall[i][j-1] == 1 and lall[i][j+1] == 1 and lall[i+1][j-1:j+2] == [1,1,1]:
        for p in range(3):
            for q in range(3):
                lcnt[i-1+p][j-1+q] += 1
#                 print(i-1+p,j-1+q, lcnt[i-1+p][j-1+q], lcnt)

ans = 0
for i in range(1, n+1):
    for j in range(1, m+1):
        if lcnt[i][j] % 2 == 1:
            ans += 1

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Solution code:
H,W =[int(i) for i in input().split()]
if H*W=1:
    print(1)
elif H==1 and W!=1:
    print(max(0, W-2))
elif W==1 and H!=1:
    print(max(0, H-2))
else:
    print(max(H-2, 0)*max(W-2, 0))

Submission status: Runtime Error

Solution code:
H, W =[int(i) for i in input().split()]
if H*W=1:
     print(1)
elif H==1 and W!=1:
     print(max(0, W-2))
elif W==1 and H!=1:
     print(max(0, H-2))
else:
     print(max(H-2, 0)*max(W-2, 0))

Submission status: Runtime Error

Solution code:
    H, W =[int(i) for i in input().split()]
    if H==1 and W!=1:
      print(max(0, W-2))
    elif W==1 and H!=1:
      print(max(0, H-2))
    else:
      print(max(H-2, 0)*max(W-2, 0))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    def int():
        return int(sys.stdin.readline().rstrip())

    def string():
        return sys.stdin.readline().rstrip()

    def map_int():
        return [int(x) for x in Scanner.string().split()]

    def string_list(n):
        return [input() for i in range(n)]

    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    def roundUp(a, b):
        return -(-a // b)

    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    def toLowerMultiple(a, x):
        return (a // x) * x

    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7


def main():
    sys.stdin = open("sample.txt")
    N, M = Scanner.map_int()
    if N == 1:
        print(M-2)
    elif M == 1:
        print(N-2)
    else:
        print((N-2) * (M-2))

    return


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return map(int, input().split())
N, A, B = inpl()
if A + B > N + 1:
    raise
    exit()
if (B == 1):
    if A == N:
        print(*list(range(1, N+1)))
    else:
        print(-1)
    exit()
elif (A == 1):
    if B == N:
        print(*list(range(N, 0, -1)))
    else:
        print(-1)
    exit()
ans = [i for i in range(N-A, N)]
i = 0
while i < N-A:
    ans += [j for j in range(i, min(i+B-(i==0), N-A))][::-1]
    i = i+B-(i==0)
print(*[i+1 for i in ans])

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
lis = [[0]*n for _ in range(m)]
for i in range(n):
  for j in range(m):
    if i == 0:
      if j == 0:
        lis[j][i] += 1
        lis[j+1][i] += 1
        lis[j][i+1] += 1
        lis[j+1][i+1] += 1
      elif j == m-1:
        lis[j][i] += 1
        lis[j-1][i] += 1
        lis[j][i+1] += 1
        lis[j-1][i+1] += 1
      else:
        lis[j][i] += 1
        lis[j-1][i] += 1
        lis[j][i+1] += 1
        lis[j-1][i+1] += 1
        lis[j+1][i] += 1
        lis[j+1][i+1] += 1
      
    elif i == n-1:
      if j == 0:
        lis[j][i] += 1
        lis[j+1][i] += 1
        lis[j][i-1] += 1
        lis[j+1][i-1] += 1
      elif j == m-1:
        lis[j][i] += 1
        lis[j-1][i] += 1
        lis[j][i-1] += 1
        lis[j-1][i-1] += 1
      else:
        lis[j][i] += 1
        lis[j-1][i] += 1
        lis[j][i-1] += 1
        lis[j-1][i-1] += 1
        lis[j+1][i] += 1
        lis[j+1][i-1] += 1
    else:
      if j == 0:
        lis[j][i] += 1
        lis[j+1][i] += 1
        lis[j][i+1] += 1
        lis[j+1][i+1] += 1
        lis[j][i-1] += 1
        lis[j+1][i-1] += 1

      elif j == m-1:
        lis[j][i] += 1
        lis[j-1][i] += 1
        lis[j][i-1] += 1
        lis[j-1][i-1] += 1 
        lis[j][i+1] += 1
        lis[j-1][i+1] += 1

      else:
        lis[j][i] += 1
        lis[j-1][i] += 1
        lis[j+1][i] += 1        
        lis[j][i-1] += 1
        lis[j-1][i-1] += 1
        lis[j+1][i-1] += 1        
        lis[j][i+1] += 1
        lis[j-1][i+1] += 1
        lis[j+1][i+1] += 1    

#print(lis)
cnt = 0
for i in range(n):
    for j in range(m):
        if lis[j][i]%2 == 1:
            cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    res = 0

    for (a, k) in [[int(x) for x in input().split()] for _ in range(n)]:
        while a >= k:
            m, u, v = a // k, (a - k * m), (m + 1)
            if a % k == 0 or u % v == 0:
                res ^= m
                break
            x = (u // v)
            a -= (x + 1) * v

    print('Takahashi' if res != 0 else 'Aoki')


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import math
from operator import itemgetter
import re
import sys
from itertools import accumulate
from collections import defaultdict
from collections import deque
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
input = sys.stdin.readline
N,M = map(int,input().split())
if N > 1 and M > 1:
    print((N-2)*(M-2))
elif N==1 and M == 1:
    print(1)
else:
    print(N+M-3))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

if n > m: swap(n, m)

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

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

Submission status: Runtime Error

Solution code:
a,b=int(input())

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def grundy(N, K):
    if N < K:
        return 0
    while N % K:
        m = N / K + 1
        N -= m
    return N / K

N = input()
ans = 0
for i in xrange(N):
    a, k = map(int, raw_input().split())
    ans ^= grundy(a, k)
print "Takahashi" if ans else "Aoki"

Submission status: Runtime Error

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

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

else:
	print(b[0]*b[1] - 2(b[0] + b[1] - 2))

Submission status: Runtime Error

Solution code:
N = int(input())
a,b,c,d = [0]*N,[0]*N,[0]*N,[0]*N
for i in range(N):
    a[i],b[i] = map(int,input().split())
for i in range(N):
    c[i],d[i] = map(int,input().split())

e = [(0,"")]*2*N
for i in range(N):
    e[a[i]] = (b[i],"R")
    e[c[i]] = (d[i],"B")

ans,p = 0,0
for i in range(2*N):
    n,c = e[i]
    if c == "R":
        p += 1
        if p > 0:
            ans += 1
    else:
        p -= 1

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
a,b,c,d = [0]*N,[0]*N,[0]*N,[0]*N
for i in range(N):
    a[i],b[i] = map(int,input().split())
for i in range(N):
    c[i],d[i] = map(int,input().split())

ans=0
for k in range(N):
    for i in range(N):
        if a[i] == k or b[i] == k:
            ans += 1
            a.pop(i)
            b.pop(i)
            break
        elif c[i] == k or d[i] == k:
            c.pop(i)
            d.pop(i)

print(ans)

Submission status: Runtime Error

Solution code:
def initBoard(rowSize, colSize):
    board = list()
    for i  in range(rowSize):
        col = [1]*colSize
        board.append(col)
    return board

def canFlip(i, j):
    return i >= 0 and i < rowSize and j >= 0 and j < colSize

def flip(board, i, j):
    if board[i][j] == 0:
        board[i][j] = 1
    elif board[i][j] == 1:
        board[i][j] = 0

def process(board, i, j):
    if canFlip(i, j):
        flip(board, i, j)
    if canFlip(i-1, j+1):
        flip(board, i-1, j+1)
    if canFlip(i, j+1):
        flip(board, i, j+1)
    if canFlip(i+1, j+1):
        flip(board, i+1, j+1)
    if canFlip(i-1, j):
        flip(board, i-1, j)
    if canFlip(i+1, j):
        flip(board, i+1, j)
    if canFlip(i-1, j-1):
        flip(board, i-1, j-1)
    if canFlip(i, j-1):
        flip(board, i, j-1)
    if canFlip(i+1, j-1):
        flip(board, i+1, j-1)

def countBack(board):
    count = 0
    for i in range(len(board)):
        for j in range(len(board[0])):
            if board[i][j] == 0: count += 1
    return count

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

rowSize = N
colSize = M
board = initBoard(rowSize, colSize)
for i in range(N):
    for j in range(M):
        process(board, i, j)
print(countBack(board))

Submission status: Runtime Error

Solution code:
n,a,b=map(int,raw_input().split())
if a+b-1>n or a*b<n :
    print -1
else :
    for i in range(a) :
        mx=min((i+1)*b,n)
        for j in range(min(b,n-i*b)) :
            print mx-j,

Submission status: Runtime Error

Solution code:
def flip(B, m, n, M, N):
#  print(m,n)
  for mm in range(m-1,m+2):
    for nn in range(n-1,n+2):
#      print("mm=", mm, "nn=", nn)
      if 0<=mm and mm<M and 0<=nn and nn<N:
        if B[mm][nn] == 0:
          B[mm][nn] = 1
        else:
          B[mm][nn] = 0
#print(input().split())
MN=list(map(int, input().split()))
B = [[0 for i in range(MN[0])] for j in range(MN[1])]
for m in range(0,MN[0]):
  for n in range(0,MN[1]):
    flip(B, m, n, MN[0], MN[1])
c = 0
for m in range(0,MN[0]):
  for n in range(0,MN[1]):
    c += B[m][n]
#print(B)
print(c)

Submission status: Runtime Error

Solution code:
def flip(B, m, n, M, N):
#  print(m,n)
  for mm in range(m-1,m+2):
    for nn in range(n-1,n+2):
      print("mm=", mm, "nn=", nn)
      if 0<=mm and mm<M and 0<=nn and nn<N:
        if B[mm][nn] == 0:
          B[mm][nn] = 1
        else:
          B[mm][nn] = 0
#print(input().split())
MN=list(map(int, input().split()))
B = [[0 for i in range(MN[0])] for j in range(MN[1])]
for m in range(0,MN[0]):
  for n in range(0,MN[1]):
    flip(B, m, n, MN[0], MN[1])
c = 0
for m in range(0,MN[0]):
  for n in range(0,MN[1]):
    c += B[m][n]
#print(B)
print(c)

Submission status: Runtime Error

Solution code:
N, A ,B = map(int,input().split())
a1 = [i+1 for i in range(A-1)]
a1.append(N)
a1 += [j for j in range(N-B,A-1,-1)]
a1 += [k for k in range(N-1,N-B,-1)]
print(*a1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, A, B = map(int,input().split())
if A+B > N+1:
    print(-1)
else:
    ans = [i+1 for i in range(A-1)]
    ans += [j for j in range(N,A-1,-1)]
    print(" ".join(map(str,ans)))