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++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>



using namespace std;
typedef long long ll;
int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}
int abs(int x){
  if(x>=0){
    return x;
  }else{
    return -x;
  }
}

int moji(char in)
{
    int ans = (int)in-(int)'a'+1;
    if((in < 1) || (in > 26)){
        ans = 100;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}





int main(){
  int N,M;
  cin>>N>>M;
  int a[N][M];
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      a[i][j]=0;


    }
  }

  for(int l=0;l<N;l++){
            for(int m=0;m<M;m++){
                if(l-1>=0&&m-1>=0){
                    if(a[l-1][m-1]==1){
                        a[l-1][m-1]=0;
                    }else{
                      a[l-1][m-1]=1;

                    }
                }
                if(l-1>=0){
                    if(a[l-1][m]==1){
                        a[l-1][m]=0;
                    }else{
                      a[l-1][m]=1;
                    }
                }
                if(m-1>=0){
                    if(a[l][m-1]==1){
                        a[l][m-1]=0;
                    }else{
                      a[l][m-1]=1;
                    }
                }
                if(l+1<N&&m+1<M){
                    if(a[l+1][m+1]==0){
                        a[l+1][m+1]=1;
                    }else{
                      a[l+1][m+1]=0;
                    }
                }
                if(l+1<N){
                    if(a[l+1][m]==0){
                        a[l+1][m]=1;
                    }else{
                      a[l+1][m]=0;
                    }
                }
                if(m+1<M){
                    if(a[l][m+1]==0){
                        a[l][m+1]=1;
                    }else{
                      a[l][m+1]=0;
                    }
                }
                if(l+1<N&&m-1>=0){
                    if(a[l+1][m-1]==0){
                        a[l+1][m-1]=1;
                    }else{
                      a[l+1][m-1]=0;
                    }
                }
                if(l-1>=0&&m+1<M){
                    if(a[l-1][m+1]==0){
                        a[l-1][m+1]=1;
                    }else{
                      a[l-1][m+1]=0;
                    }
                }
                if(a[l][m]==0){
                  a[l][m]=1;
                }else{
                  a[l][m]=0;
                }



                
            }
        }
        int sum=0;
        for(int i=0;i<N;i++){
          for(int j=0;j<M;j++){
            if(a[i][j]==1){
              sum++;
            }
          }
        }
        cout<<sum<<endl;


  
}