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 Java7 (OpenJDK 1.7.0) (judge verdict: Time Limit Exceeded)


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		//		new Main().solveA();
		//		new Main().solveB();
		new Main().solveC();

		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;

		String[] wkArray = new String[3];

		try {
			StringBuffer buff = new StringBuffer();
			scanner = new Scanner(System.in);
			for (int i = 0; i < 3; i++) {
				wkArray[i] = scanner.next();
			}

			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < 3; j++) {
					if (i == j) {
						buff.append((wkArray[i].toCharArray())[j]);
					}
				}
			}

			System.out.println(buff.toString());

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;

		int startNum = 0;
		int endNum = 0;

		try {
			scanner = new Scanner(System.in);
			startNum = scanner.nextInt();
			endNum = scanner.nextInt();

			int count = 0;
			for (int i = startNum; i <= endNum; i++) {
				char[] num = Integer.toString(i).toCharArray();
				if (num[0] == num[4] && num[1] == num[3]) {
					count++;
				}
			}

			System.out.println(count);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void returnCard(int cardNumN, int cardNumM) {

		revertCard(cardNumN, cardNumM);

		if (cardNumN - 1 >= 0) {
			revertCard(cardNumN - 1, cardNumM);
		}
		if (cardNumN - 1 >= 0 && cardNumM + 1 < numM) {
			revertCard(cardNumN - 1, cardNumM + 1);
		}
		if (cardNumM + 1 < numM) {
			revertCard(cardNumN, cardNumM + 1);
		}
		if (cardNumN + 1 < numN && cardNumM + 1 < numM) {
			revertCard(cardNumN + 1, cardNumM + 1);
		}
		if (cardNumN + 1 < numN) {
			revertCard(cardNumN + 1, cardNumM);
		}
		if (cardNumN + 1 < numN && cardNumM - 1 >= 0) {
			revertCard(cardNumN + 1, cardNumM - 1);
		}
		if (cardNumM - 1 >= 0) {
			revertCard(cardNumN, cardNumM - 1);
		}
		if (cardNumN - 1 >= 0 && cardNumM - 1 >= 0) {
			revertCard(cardNumN - 1, cardNumM - 1);
		}

	}

	private void revertCard(int cardNumN, int cardNumM) {

		long wk = masu.get(cardNumN).get(cardNumM) * -1;
		masu.get(cardNumN).set(cardNumM, wk);
	}

	private List<List<Long>> masu;
	private int numN = 0;
	private int numM = 0;

	private void solveC() {
		Scanner scanner = null;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			numM = scanner.nextInt();
			masu = new ArrayList<List<Long>>();

			for (int i = 0; i < numN; i++) {
				List<Long> wkList = new ArrayList<Long>();
				for (int j = 0; j < numM; j++) {
					wkList.add((long) -1);
				}
				masu.add(wkList);
			}

			for (int i = 0; i < numN; i++) {
				for (int j = 0; j < numM; j++) {
					returnCard(i, j);
				}
			}
			int result = 0;
			for (int i = 0; i < numN; i++) {
				for (int j = 0; j < numM; j++) {
					if (masu.get(i).get(j) == 1) {
						result++;
					}
				}
			}

			System.out.println(result);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}