Go: package main

import "fmt"

func main() {
	//部屋を生成
	var H int

	fmt.Scan(&H)
	room := [][4]bool{}

	for i := 0; i < H; i++ {
		room = append(room, [4]bool{})
	}

	//荷物のおけない区画を設定
	var N int
	fmt.Scan(&N)
	for i := 0; i < N; i++ {
		var x, y int
		fmt.Scan(&x, &y)
		room[y][x] = true //ものがある状態を真とする
	}
	//荷物を配置
	var count int
	for i := 0; i < 3; i++ {
		for j := 0; j < H-1; j++ {
			if !room[j][i] && !room[j+1][i] && !room[j][i+1] && !room[j+1][i+1] {
				room[j][i] = true
				room[j+1][i] = true
				room[j][i+1] = true
				room[j+1][i+1] = true
				count++
			}
		}
	}
	fmt.Println(count)
}

C++: #include <bits/stdc++.h>

using namespace std;

int H, N;
int ngmask[1000];
int dp[1000][1 << 4];

int rec(int idx, int upbit)
{
  if(idx == H) return (0);
  if(~dp[idx][upbit]) return (dp[idx][upbit]);
  int ret = rec(idx + 1, ngmask[idx]);
  for(int i = 0; i < 3; i++) {
    if((upbit >> i) & 3) continue;
    if((ngmask[idx] >> i) & 3) continue;
    ret = max(ret, rec(idx + 1, (3 << i) | ngmask[idx]) + 1);
  }
  if(ngmask[idx] == 0 && upbit == 0) {
    ret = max(ret, rec(idx + 1, (1 << 4) - 1) + 2);
  }
  return (dp[idx][upbit] = ret);
}

int main()
{
  cin >> H >> N;
  for(int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    ngmask[y] |= 1 << x;
  }
  memset(dp, -1, sizeof(dp));
  cout << rec(1, ngmask[0]) << endl;
}

C++: #include <cstdio>

const int MAX_RC = 30000;
int R, N;
const int K = 4;
bool grid[MAX_RC][K];

int main() {
  scanf("%d %d", &R, &N);
  for (int i = 0; i < N; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    grid[y][x] = 1;
  }
  int num = 0;
  for (int r = 0; r < R - 1; ++r) {
    for (int c = 0; c < K - 1; ++c) {
      if (!grid[r][c] && !grid[r + 1][c] && !grid[r][c + 1] && !grid[r + 1][c + 1]) {
        grid[r][c] = grid[r+ 1][c] = grid[r][c + 1] = grid[r + 1][c + 1] = 1;
        num++;
      }
    }
  }
  printf("%d\n", num);
}

C++: #include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for( int i = 0; i < (n); i++ )
#define Rrep(i, a, n) for( int i = (a); i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

int H, N;
bool used[10001][4];
int dp[10001][3][3][3][3];

int dfs(int h, int a, int b, int c, int d) {
  if ( h == H ) return 0LL;
  if ( dp[h][a][b][c][d] >= 0 ) return dp[h][a][b][c][d];

  int ret = 0;
  int a2 = 1, b2 = 1, c2 = 1, d2 = 1;
  if ( used[h][0] ) a2 = 2;
  if ( used[h][1] ) b2 = 2;
  if ( used[h][2] ) c2 = 2;
  if ( used[h][3] ) d2 = 2;

  if ( a == 1 && b == 1 && a2 == 1 && b2 == 1 && c == 1 && d == 1 && c2 == 1 && d2 == 1 ) ret = max(ret, dfs(h+1, 2, 2, 2, 2) + 2);
  if ( a == 1 && b == 1 && a2 == 1 && b2 == 1 ) ret = max(ret, dfs(h+1, 2, 2, c2, d2) + 1);
  if ( b == 1 && c == 1 && b2 == 1 && c2 == 1 ) ret = max(ret, dfs(h+1, a2, 2, 2, d2) + 1);
  if ( c == 1 && d == 1 && c2 == 1 && d2 == 1 ) ret = max(ret, dfs(h+1, a2, b2, 2, 2) + 1);
  ret = max(ret, dfs(h+1, a2, b2, c2, d2));

  return dp[h][a][b][c][d] = ret;
}

signed main() {
  cin >> H >> N;
  Rep(i, N) {
    int x, y;
    cin >> x >> y;
    used[y][x] = true;
  }
  memset(dp, -1, sizeof(dp));

  cout << dfs(0, 0, 0, 0, 0) << endl;
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//

int H, N;
int x[41234], y[41234];
int dp[41234][1<<4];

int main() {
	cin >> H >> N;
	
	set<pii> ss; // x, y
	REP(i, N) {
		scanf("%d %d", x + i, y + i);
		ss.insert(pii(x[i], y[i]));
	}
	
	memset(dp, -1, sizeof(dp));
	
	dp[0][0] = 0;
	
	REP(i, H - 1) {
		REP(j, 1<<4) {
			if (dp[i][j] == -1) continue;
			int ng = j;
			REP(k, 4) {
				ng |= (ss.find(pii(k, i)) != ss.end()) << k;
				ng |= (ss.find(pii(k, i + 1)) != ss.end()) << k;
			}
			
			int ok = 15 ^ ng;
			
			chmax(dp[i + 1][0], dp[i][j]);
			if ((ok & 3) == 3) chmax(dp[i + 1][3], dp[i][j] + 1);
			if ((ok & 6) == 6) chmax(dp[i + 1][6], dp[i][j] + 1);
			if ((ok & 12) == 12) chmax(dp[i + 1][12], dp[i][j] + 1);
			if ((ok & 15) == 15) chmax(dp[i + 1][15], dp[i][j] + 2);
		}
	}
	
	int ans = 0;
	REP(i, 1<<4) chmax(ans, dp[H - 1][i]);
	cout << ans << endl;
	
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
//
struct poi{
  int X;int Y;int Z;
  bool operator<(const poi&R)const{
    return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
  }
};
//
//
int main(){
	int H,N;
	int M[10000][4];
	cin>>H>>N;
	FOR(i,0,H){
		FOR(j,0,4){
			M[i][j]=0;
		}
	}
	FOR(i,0,N){
		int X,Y;
		cin>>X>>Y;
		M[Y][X]=-1;
	}
	int ans=0;
	FOR(i,0,H-1){
		if(M[i][0]==0&&M[i][1]==0&&M[i][2]==0&&M[i][3]==0){
			if(M[i+1][0]==0&&M[i+1][1]==0&&M[i+1][2]==0&&M[i+1][3]==0){
				ans+=2;
				FOR(j,0,2){
					FOR(k,0,4){
						M[i+j][k]=1;
					}
				}
			}
		}
	}
	FOR(i,0,H-3){
		if(M[i][0]==0&&M[i][1]==0&&M[i+1][0]==1&&M[i+1][1]==1&&M[i+2][0]==1&&M[i+2][1]==1&&M[i+3][0]==0&&M[i+3][1]==0){
			ans++;
			M[i][0]=1;M[i][1]=1;
			M[i+3][0]=1;M[i+3][1]=1;
		}else if(M[i][2]==0&&M[i][3]==0&&M[i+1][2]==1&&M[i+1][3]==1&&M[i+2][0]==1&&M[i+2][3]==1&&M[i+3][2]==0&&M[i+3][3]==0){
			ans++;
			M[i][2]=1;M[i][3]=1;
			M[i+3][2]=1;M[i+3][3]=1;
		}
	}
	FOR(i,0,H-1){
		if(M[i][0]==0&&M[i][1]==0&&M[i+1][0]==0&&M[i+1][1]==0){
			FOR(j,0,2){
				FOR(k,0,2){
					M[i+j][k]=1;
				}
			}
			ans++;
		}else if(M[i][1]==0&&M[i][2]==0&&M[i+1][1]==0&&M[i+1][2]==0){
			FOR(j,0,2){
				FOR(k,1,3){
					M[i+j][k]=1;
				}
			}
			ans++;
		}else if(M[i][2]==0&&M[i][3]==0&&M[i+1][2]==0&&M[i+1][3]==0){
			FOR(j,0,2){
				FOR(k,2,4){
					M[i+j][k]=1;
				}
			}
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}