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 C# (Mono 4.6.2.0) (judge verdict: Accepted)


using System.Collections;
using System.Text;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System;
using System.Numerics;


class Program
{

    static void Main()
    {
        #region 入力
        int[] NM = ReadInts;
        #endregion

        int N = NM[0];
        int M = NM[1];


        if (N == 1||M == 1)
        {
            if(N == M)
            {
                WriteLine(1);
            }
            else
            {
                WriteLine(Max(N, M) - 2);
            }
        }
        else
        {
            WriteLine((long)(N - 2) * (long)(M - 2));
        }
        ReadLine();
    }

    struct Vector2Int
    {
        public Vector2Int(int x, int y)
        {
            X = x;
            Y = y;
        }
        public int X;
        public int Y;
        public double Magnitude => Math.Sqrt(X * X + Y * Y);

        public static Vector2Int zero => new Vector2Int(0, 0);
        public static Vector2Int u => new Vector2Int(0, 1);
        public static Vector2Int r => new Vector2Int(1, 0);
        public static Vector2Int d => new Vector2Int(0, -1);
        public static Vector2Int l => new Vector2Int(-1, 0);
        public static Vector2Int[] AllDirections => new Vector2Int[4] { u, r, d, l };

        public static Vector2Int operator +(Vector2Int a, Vector2Int b)
        {
            return new Vector2Int(a.X + b.X, a.Y + b.Y);
        }
        public static Vector2Int operator -(Vector2Int a, Vector2Int b)
        {
            return new Vector2Int(a.X - b.X, a.Y - b.Y);
        }
        public static bool operator ==(Vector2Int a, Vector2Int b)
        {
            return a.X == b.X && a.Y == b.Y;
        }
        public static bool operator !=(Vector2Int a, Vector2Int b)
        {
            return a.X != b.X || a.Y != b.Y;
        }
        public static Vector2Int operator *(Vector2Int v, int n)
        {
            return new Vector2Int(v.X * n, v.Y * n);
        }
        public static Vector2Int operator *(int n, Vector2Int v)
        {
            return new Vector2Int(v.X * n, v.Y * n);
        }
    }
    struct Vector3Int
    {
        public Vector3Int(int x, int y, int z)
        {
            X = x;
            Y = y;
            Z = z;
        }
        public int X;
        public int Y;
        public int Z;

        public double Magnitude => Math.Sqrt(X * X + Y * Y + Z * Z);

        public static Vector3Int zero => new Vector3Int(0, 0, 0);
        public static Vector3Int u => new Vector3Int(0, 1, 0);
        public static Vector3Int r => new Vector3Int(1, 0, 0);
        public static Vector3Int d => new Vector3Int(0, -1, 0);
        public static Vector3Int l => new Vector3Int(-1, 0, 0);

        public static Vector3Int operator +(Vector3Int a, Vector3Int b)
        {
            return new Vector3Int(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
        }
        public static Vector3Int operator -(Vector3Int a, Vector3Int b)
        {
            return new Vector3Int(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
        }
        public static bool operator ==(Vector3Int a, Vector3Int b)
        {
            return a.X == b.X && a.Y == b.Y && a.Z == b.Z;
        }
        public static bool operator !=(Vector3Int a, Vector3Int b)
        {
            return a.X != b.X || a.Y != b.Y || a.Z != b.Z;
        }
        public static Vector3Int operator *(Vector3Int v, int n)
        {
            return new Vector3Int(v.X * n, v.Y * n, v.Z * n);
        }
        public static Vector3Int operator *(int n, Vector3Int v)
        {
            return new Vector3Int(v.X * n, v.Y * n, v.Z * n);
        }
    }

    #region Reader
    static Vector2Int ReVec2Int { get {
            string[] s = Console.ReadLine().Split(' ');
            return new Vector2Int(int.Parse(s[0]), int.Parse(s[1]));
        } }
    static Vector2Int[] ReadVec2Ints(int n)
    {
        List<Vector2Int> list = new List<Vector2Int>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReadInts;
            list.Add(new Vector2Int(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static HashSet<Vector2Int> ReadVec2IntHash(int n)
    {
        HashSet<Vector2Int> hash = new HashSet<Vector2Int>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReadInts;
            hash.Add(new Vector2Int(ab[0], ab[1]));
        }
        return hash;
    }
    static string ReStr => Console.ReadLine();
    static string[] ReadStrs => Console.ReadLine().Split(' ');
    static int ReadInt => Convert.ToInt32(Console.ReadLine());
    static int[] ReadInts => Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
    static long ReLong => Convert.ToInt64(Console.ReadLine());
    static long[] ReLongs => Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
    static long[,] ReLongMatrix(int r, int c)
    {
        var mat = new long[r, c];
        for (int i = 0; i < r; ++i)
        {
            var x = ReLongs;
            for (int j = 0; j < c; ++j)
            {
                mat[i, j] = x[j];
            }
        }
        return mat;
    }
    static Tuple<string, string>[] ReTupleStr(int n)
    {
        List<Tuple<string, string>> list = new List<Tuple<string, string>>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReadStrs;
            list.Add(new Tuple<string, string>(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static Tuple<long, long>[] ReTupleLong(int n)
    {
        List<Tuple<long, long>> list = new List<Tuple<long, long>>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReLongs;
            list.Add(new Tuple<long, long>(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static Tuple<int, int>[] ReTupleInt(int n)
    {
        List<Tuple<int, int>> list = new List<Tuple<int, int>>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReadInts;
            list.Add(new Tuple<int, int>(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static Tuple<double, double>[] ReTupleDouble(int n)
    {
        List<Tuple<double, double>> list = new List<Tuple<double, double>>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReLongs;
            list.Add(new Tuple<double, double>(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static Dictionary<int, HashSet<int>> ReAdjacencyList(int N, int M)
    {
        Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
        for (int i = 0; i <= N; ++i)
        {
            dict.Add(i, new HashSet<int>());
        }
        for (int i = 0; i < M; ++i)
        {
            var ab = ReadInts;
            dict[ab[0]].Add(ab[1]);
            dict[ab[1]].Add(ab[0]);
        }
        return dict;
    }
    #endregion
}