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 j := 0; j < H-1; j++ {
		for i := 0; i < 3; i++ {

			if !room[j][i] && !room[j+1][i] && !room[j][i+1] && !room[j+1][i+1] {
				//if i!=0&&i!=2&&j!=H-3{
				//	if !room[j+1][i-1]&&!room[j+1][i+2]{
				//		if !room[j+2][0]&&!room[j+2][1]&&!room[j+2][2]&&!room[j+2][3]{
				//			break
				//		}
				//	}
				//}
				room[j][i] = true
				room[j+1][i] = true
				room[j][i+1] = true
				room[j+1][i+1] = true
				count++
			}
		}
	}

	var openCount int
	for _,v:=range room{
		openCount=0
		for _,v2:=range v{
			if !v2{
				openCount++
			}

		}
		if openCount>=3{
			count++
		}
	}
	fmt.Println(count)
}

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

int h, n;
vector<int> b;

int dp[101010][10];

int dfs(int i = 1, int bit = 0) {
  if (i == h) {
    return 0;
  }
  bit |= b[i];

  int &ret = dp[i][bit];
  if (~ret)
    return ret;

  ret = 0;
  if (bit == 0)
    ret = max(ret, dfs(i + 1, 0b111) + 2);
  if ((bit & (0b100)) == 0)
    ret = max(ret, dfs(i + 1, 0b110) + 1);
  if ((bit & (0b010)) == 0)
    ret = max(ret, dfs(i + 1, 0b111) + 1);
  if ((bit & (0b001)) == 0)
    ret = max(ret, dfs(i + 1, 0b011) + 1);
  ret = max(ret, dfs(i + 1, 0));

  return ret;
}

int main() {
  memset(dp, -1, sizeof(dp));
  cin >> h >> n;

  int ei[4] = {0b100, 0b110, 0b011, 0b001};
  b.assign(h + 1, 0);
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    b[y + 1] |= ei[x];
    b[y] |= ei[x];
  }

  cout << dfs() << endl;
}

C++: #include<algorithm>
#include <bits/stdc++.h>
#include <math.h>
#include <queue>
using namespace std;
int ma[100000][4];
int main(void){
	
	int h,n,x,y,ans=0;
	cin>>h>>n;
	for(int i=0;i<n;i++){
		cin>>y>>x;
		ma[x][y]=1;
	}
	for(int i=0;i<h-1;i++){
		for(int j=0;j<3;j++){
			if(ma[i][j]!=1&&ma[i+1][j]!=1&&ma[i][j+1]!=1&&ma[i+1][j+1]!=1){
				ans++;
				ma[i][j]=1;
				ma[i+1][j]=1;
				ma[i][j+1]=1;
				ma[i+1][j+1]=1;
			}
		}
	}
  
	cout<<ans<<endl;
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
int h,n;
int si[10005][4];
int dp[10005][5];
int main(void){
   cin>>h>>n;
   for(int i=0;i<n;i++){
       int a,b;
       cin>>a>>b;
       for(int j=b;j>=b-1;j--){
           for(int k=a;k>=a-1;k--){
               if(k>=0&&j>=0&&k<3&&j<h-1)si[j+1][k]=1;
           }
       }
   }
   
   for(int i=1;i<h;i++){
       if(si[i][0]==1||si[i][2]==1)si[i][3]=1;
   }
   
   
   
   for(int i=1;i<=h;i++){
       if(si[i][0]==0)dp[i][0]=max(dp[i-1][2],dp[i-1][4])+1;
       if(si[i][1]==0)dp[i][1]=dp[i-1][4]+1;
       if(si[i][2]==0)dp[i][2]=max(dp[i-1][0],dp[i-1][4])+1;
       if(si[i][3]==0)dp[i][3]=dp[i-1][4]+2;
       for(int j=0;j<5;j++)dp[i][4]=max(dp[i][4],dp[i-1][j]);
   }
   cout<<dp[h][4]<<endl;
}

C++: #include<bits/stdc++.h>
using namespace std;
bool mp[10005][4];

int main(){
  ios_base::sync_with_stdio(false);
  int h,n,x,y;
  for(int i=0;i<10005;i++){
    for(int j=0;j<4;j++){
      mp[i][j] = true;
    }
  }
  cin >> h >> n;
  
  for(int i=0;i<n;i++){
    cin >> x >> y;
    mp[y][x] = false;
  }

  int ans = 0;
  for(int i=0;i<h-1;i++){
    if(mp[i][0] && mp[i][1] && mp[i+1][0] && mp[i+1][1]){ //左に正方形が作れるとき
      mp[i][0] = mp[i][1] = mp[i+1][0] = mp[i+1][1] = false;
      ans++;
    }
    if(mp[i][2] && mp[i][3] && mp[i+1][2] && mp[i+1][3]){ //右に正方形が作れるとき
      mp[i][2] = mp[i][3] = mp[i+1][2] = mp[i+1][3] = false;
      ans++;
    }
    if(mp[i][1] && mp[i][2] && mp[i+1][1] && mp[i+1][2]){ //真ん中に正方形が作れるとき
      int j=0;
      while(mp[i+1+j][0] && mp[i+1+j][1] && mp[i+1+j][2] && mp[i+1+j][3]) j++;
      if(j != 0 && j%2 == 1){
	mp[i][1] = mp[i][2] = mp[i+1][1] = mp[i+1][2] = false;
	ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

C++: #include <iostream>

using namespace std;

bool mid(int y);
bool can_put(int y, int x);

int h;
bool mas[10005][4];

int main()
{
    int n;
    int y, x;
    int ans = 0;

    cin >> h >> n;
    for (int i = 0; i < n; i++) {
        cin >> x >> y;

        mas[y][x] = true;
    }

    for (int i = 0; i < h - 1; i++) {
        if (can_put(i, 0)) {
            ans++;

            mas[i][0] = mas[i][1] = mas[i + 1][0] = mas[i + 1][1] = true;
        }
        if (can_put(i, 2)) {
            ans++;

            mas[i][2] = mas[i][3] = mas[i + 1][2] = mas[i + 1][3] = true;
        }
        if (can_put(i, 1) && mid(i)) {
            ans++;

            mas[i][1] = mas[i][2] = mas[i + 1][1] = mas[i + 1][2] = true;
        }
    }

    cout << ans << endl;

    return 0;
}


bool mid(int y)
{
    int i = 0;
    ++y;
    while (y + i < h && !(mas[y + i][0] || mas[y + i][1] || mas[y + i][2] || mas[y + i][3])) i++;

    return i == 0 || i % 2;
}
    
bool can_put(int y, int x)
{
    return !(mas[y][x] || mas[y][x + 1] || mas[y + 1][x] || mas[y + 1][x + 1]);
}

C++: //============================================================================
// Name        : AOJ.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>

using namespace std;

int h,n;
int dp[16][10001]={};
int d[10001]={};

int calc(int i,int m){
	if(dp[i][m]>=0)return dp[i][m];
	dp[i][m]=0;
	for(int j=0;j<16;++j)dp[i][m]=max(dp[i][m],calc(j,m-1));
	if(((3+d[m])==i)&&((3&d[m-1])==0)){
		dp[i][m]=max(dp[i][m],1+calc(0,m-1));
		dp[i][m]=max(dp[i][m],1+calc(4,m-1));
		dp[i][m]=max(dp[i][m],1+calc(8,m-1));
		dp[i][m]=max(dp[i][m],1+calc(12,m-1));
	}
	if(((6+d[m])==i)&&((6&d[m-1])==0)){
		dp[i][m]=max(dp[i][m],1+calc(0,m-1));
		dp[i][m]=max(dp[i][m],1+calc(1,m-1));
		dp[i][m]=max(dp[i][m],1+calc(8,m-1));
		dp[i][m]=max(dp[i][m],1+calc(9,m-1));
	}
	if(((12+d[m])==i)&&((12&d[m-1])==0)){
		dp[i][m]=max(dp[i][m],1+calc(0,m-1));
		dp[i][m]=max(dp[i][m],1+calc(1,m-1));
		dp[i][m]=max(dp[i][m],1+calc(2,m-1));
		dp[i][m]=max(dp[i][m],1+calc(3,m-1));
	}
	if(((15+d[m])==i)&&((6&d[m-1])==0)){
		dp[i][m]=max(dp[i][m],2+calc(0,m-1));
	}
	return dp[i][m];
}
int main() {
	cin>>h>>n;

	for(int i=0;i<10001;++i){
		for(int j=0;j<16;++j){
			dp[j][i]=-1;
		}
	}
	int x,y;
	for(int i=0;i<n;++i){
		cin>>x>>y;
		x=(1<<x);
		for(int j=0;j<16;++j){
			if((j&x)!=x)dp[j][y]=0;
		}
		d[y]+=x;
	}

	for(int j=0;j<16;++j)dp[j][0]=0;


	int total=0;
	for(int i=0;i<16;++i)total=max(total,calc(i,h));
	cout<<total<<endl;
	return 0;
}