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++
			}
		}
	}
	//for _,v:=range room{
	//	for _,v2:=range v{
	//		if !v2 {
	//			fmt.Print("◯")
	//		}else{
	//			fmt.Print("☓")
	//		}
	//	}
	//	fmt.Println()
	//}
	fmt.Println(count)
}

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;
					}
				}
			}
		}
	}
	int now=0;
	while(now<H){
		if(M[now][0]==0&&M[now][1]==0){
			int mem=now;
			now++;
			if(now==H){
				break;
			}
			while(now<H&&M[now][0]==1&&M[now][1]==1){
				now++;
			}
			if(now==H){
				break;
			}
			if(M[now][0]==0&&M[now][1]==0){
				M[mem][0]=1;M[mem][1]=1;
				M[now][0]=1;M[now][1]=1;
				ans++;
			}
			now++;
		}else{
			now++;
		}
	}
	now=0;
	while(now<H){
		if(M[now][2]==0&&M[now][3]==0){
			int mem=now;
			now++;
			if(now==H){
				break;
			}
			while(now<H&&M[now][2]==1&&M[now][3]==1){
				now++;
			}
			if(now==H){
				break;
			}
			if(M[now][2]==0&&M[now][3]==0){
				M[mem][2]=1;M[mem][3]=1;
				M[now][2]=1;M[now][3]=1;
				ans++;
			}
			now++;
		}else{
			now++;
		}
	}
	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;
}

C++: #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main(){
  int H, N;
  cin >> H >> N;
  constexpr const int M = 1<<4;
  vector<int> dp(M,-1);
  vector<vector<int>> X(H);
  for(int i = 0; i < N; ++i){
    int x, y;
    cin >> x >> y;
    X[y].push_back(x);
  }
  int bit = 0;
  for(auto x : X[0]){
    bit |= 1<<x;
  }
  dp[bit] = 0;
  for(int i = 0; i < H-1; ++i){
    vector<int> dp_(M,-1);
    int bit_ = 0;
    for(auto x : X[i+1]){
      bit_ |= 1<<x;
    }
    for(int j = 0; j < M; ++j){
      if((bit&j) != bit) continue;
      for(int k = 0; k < 3; ++k){
        if(dp[j] < 0) continue;
        int tmp = bit_;
        if((j>>k&1) or (j>>(k+1)&1)) continue;
        if((tmp>>k&1) or (tmp>>(k+1)&1)) continue;
        tmp |= 1<<k;
        tmp |= 1<<(k+1);
        dp_[tmp] = dp[j]+1;
      }
    }
    if(bit == 0 and bit_ == 0 and dp[0] >= 0){
      dp_[M-1] = dp[0]+2;
    }
    dp_[bit_] = max(dp_[bit_],*max_element(dp.begin(), dp.end()));
    swap(bit,bit_);
    swap(dp,dp_);
  }
  cout << *max_element(dp.begin(), dp.end()) << endl;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#define ll long long
#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--)
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;
	}
};
//
ll GCD(ll a,ll b){
	return (b==0)?(a):(GCD(b,a%b));
}
ll LCM(ll a,ll b){
	return a/GCD(a,b)*b;
}
//
int H,N;
int ok[10000][4];
int DP[10000][5];
int main(){
	cin>>H>>N;
	FOR(i,0,H){
		FOR(j,0,4){
			ok[i][j]=1;
		}
	}
	FOR(i,0,N){
		int X,Y;
		cin>>X>>Y;
		ok[Y][X]=0;
	}
	/*
	cout<<endl;
	FOR(i,0,H){
		FOR(j,0,4){
			cout<<ok[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
	*/
	//
	if(ok[0][0]&&ok[0][1]&&ok[1][0]&&ok[1][1]){
		DP[0][1]=1;
	}
	if(ok[0][1]&&ok[0][2]&&ok[1][1]&&ok[1][2]){
		DP[0][2]=1;
	}
	if(ok[0][2]&&ok[0][3]&&ok[1][2]&&ok[1][3]){
		DP[0][3]=1;
	}
	if(ok[0][0]&&ok[0][1]&&ok[1][0]&&ok[1][1]&&ok[0][2]&&ok[0][3]&&ok[1][2]&&ok[1][3]){
		DP[0][4]=2;
	}
	//
	if(ok[1][0]&&ok[1][1]&&ok[2][0]&&ok[2][1]){
		DP[1][1]=DP[0][3]+1;
	}
	if(ok[1][1]&&ok[1][2]&&ok[2][1]&&ok[2][2]){
		DP[1][2]=1;
	}
	if(ok[1][2]&&ok[1][3]&&ok[2][2]&&ok[2][3]){
		DP[1][3]=DP[0][1]+1;
	}
	if(ok[1][0]&&ok[1][1]&&ok[2][0]&&ok[2][1]&&ok[1][2]&&ok[1][3]&&ok[2][2]&&ok[2][3]){
		DP[1][4]=2;
	}
	//
	FOR(i,2,H-1){
		DP[i][0]=max({DP[i-2][0],DP[i-2][1],DP[i-2][2],DP[i-2][3],DP[i-2][4]});
		DP[i][0]=max({DP[i-1][0],DP[i-1][1],DP[i-1][2],DP[i-1][3],DP[i-1][4]});
		DP[i][1]=max({DP[i-1][3],DP[i-2][0],DP[i-2][1],DP[i-2][2],DP[i-2][3],DP[i-2][4]});
		DP[i][2]=max({DP[i-2][0],DP[i-2][1],DP[i-2][2],DP[i-2][3],DP[i-2][4]});
		DP[i][3]=max({DP[i-1][1],DP[i-2][0],DP[i-2][1],DP[i-2][2],DP[i-2][3],DP[i-2][4]});
		DP[i][4]=max({DP[i-2][0],DP[i-2][1],DP[i-2][2],DP[i-2][3],DP[i-2][4]});
		if(ok[i][0]&&ok[i][1]&&ok[i+1][0]&&ok[i+1][1]){
			DP[i][1]++;
		}else{
			DP[i][1]=max({DP[i][1],DP[i-1][0],DP[i-1][1],DP[i-1][2],DP[i-1][3],DP[i-1][4]});
		}
		if(ok[i][1]&&ok[i][2]&&ok[i+1][1]&&ok[i+1][2]){
			DP[i][2]++;
		}else{
			DP[i][2]=max({DP[i][2],DP[i-1][0],DP[i-1][1],DP[i-1][2],DP[i-1][3],DP[i-1][4]});
		}
		if(ok[i][2]&&ok[i][3]&&ok[i+1][2]&&ok[i+1][3]){
			DP[i][3]++;
		}else{
			DP[i][3]=max({DP[i][3],DP[i-1][0],DP[i-1][1],DP[i-1][2],DP[i-1][3],DP[i-1][4]});
		}
		if(ok[i][0]&&ok[i][1]&&ok[i+1][0]&&ok[i+1][1]&&ok[i][2]&&ok[i][3]&&ok[i+1][2]&&ok[i+1][3]){
			DP[i][4]+=2;
		}else{
			DP[i][4]=max({DP[i][4],DP[i-1][0],DP[i-1][1],DP[i-1][2],DP[i-1][3],DP[i-1][4]});
		}
	}
	int ans=0;
	/*
	FOR(i,0,H){
		FOR(j,0,5){
			cout<<DP[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
	*/
	FOR(i,0,5){
		ans=max(ans,DP[H-2][i]);
	}
	cout<<ans<<endl;
	return 0;
}