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

Solution in JavaScript (node.js v5.12) (judge verdict: Accepted)

"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const M = parseInt(arg[0].split(" ")[1]);
    
    let answer = 0;
    
    if(N === 1 && M === 1) {
        answer = 1;
    } else if(N === 1) {
        answer = M - 2;
    } else if(M === 1) {
        answer = N - 2;
    } else {
        answer = (N - 2) * (M - 2);
    }
    
    // 桁溢れ対策  original (id: macco さん)
    if (answer > Number.MAX_SAFE_INTEGER) {

    const multi_biggerInt = (a, b) => {
      const num1 = String(a).split('').map(n => Number(n)).reverse();
      const num2 = String(b).split('').map(n => Number(n)).reverse();

      let ans = [...Array(num1.length + num2.length)].fill(0);

      const checkCarry = () => {
        for (let i = 0; i < ans.length; i++) {
          if (ans[i] >= 10) {
            const upper = Number(String(ans[i]).split('')[0]);
            const lower = Number(String(ans[i]).split('')[1]);

            ans[i - 1] += upper;
            ans[i] = lower;
          }
        }
      }

      for (let i = 0; i < num1.length; i++) {
        for (let j = 0; j < num2.length; j++) {
          const pro   = num1[i] * num2[j];
          const digit = ans.length - (i + j) - 1;

          ans[digit] += pro;
          checkCarry();
        }
      }

      for (let i = 0; i < ans.length; i++) {
        if (ans[i] !== 0) {
          ans = ans.slice(i);
          break;
        }
      }

      return ans.join('');
      }

      answer = multi_biggerInt(Math.abs(N - 2), Math.abs(M - 2));
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));