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<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
bool used[10005][4]={false};
ll dp[10005][16]={0};
void check(bool a){
  cout<<(a?"y ":"n ");
}
int main(){
  for(int i=0;i<10005;i++) for(int j=0;j<4;j++) used[i][j]=false;
  ll h,n;
  cin>>h>>n;
  for(int i=0;i<n;i++){
    ll x,y;
    cin>>x>>y;
    used[y][x]=true;
  }
  bool f=false;
  for(int i=0;i<=h;i++) for(int j=0;j<16;j++) dp[i][j]=0;
  for(int i=0;i<h-1;i++){
    for(int j=0;j<16;j++){
      bool n12=true,n23=true,n34=true,n112=false,n123=false,n134=false;
      if(j>=8||(j%8)>=4) n34=false;
      if((j%8)>=4||(j%4)>=2) n23=false;
      if((j%4)>=2||(j%2)==1) n12=false;
        if(used[i][0]) n12=false;
        if(used[i][1]){
          n12=false;
          n23=false;
        }
        if(used[i][2]){
          n23=false;
          n34=false;
        }
        if(used[i][3]) n34=false;

      if(!used[i+1][0]&&!used[i+1][1]) n112=true;
      if(!used[i+1][1]&&!used[i+1][2]) n123=true;
      if(!used[i+1][2]&&!used[i+1][3]) n134=true;
      if(n12&n112){
        int nb=3;
        if(used[i+1][2]) nb+=4;
        if(used[i+1][3]) nb+=8;
        dp[i+1][nb]=max(dp[i+1][nb],dp[i][j]+1);
      //  if(nb==14) cout<<"NB 15 p01:"<<i<<" "<<j<<endl;
      }
      if(n23&&n123){
        int nb=6;
        if(used[i+1][0]) nb+=1;
        if(used[i+1][3]) nb+=8;
        dp[i+1][nb]=max(dp[i+1][nb],dp[i][j]+1);
//        if(nb==14) cout<<"NB 15 p02:"<<i<<" "<<j<<endl;

      }
      if(n34&&n134){
        int nb=12;
        if(used[i+1][0]) nb+=1;
        if(used[i+1][1]) nb+=2;
        dp[i+1][nb]=max(dp[i+1][nb],dp[i][j]+1);
  //      if(nb==14) cout<<"NB 15 p03:"<<i<<" "<<j<<endl;
      }
      if(n12&&n112&&n34&&n134){
        dp[i+1][15]=max(dp[i+1][15],dp[i][j]+2);
              //   cout<<"NB 15 p04:"<<i<<" "<<j<<endl;
      }
      int knb=0;
      if(used[i+1][0]) knb+=1;
      if(used[i+1][1]) knb+=2;
      if(used[i+1][2]) knb+=4;
      if(used[i+1][3]) knb+=8;
      dp[i+1][knb]=max(dp[i+1][knb],dp[i][j]);
    }
  }
  /*cout<<"idx:";
  for(int j=0;j<16;j++) printf("%3d",j);
  cout<<endl;
  for(int i=0;i<h;i++){
    cout<<i<<"  :";
    for(int j=0;j<16;j++) printf("%3lld",dp[i][j]);
    cout<<endl;
  }*/

  ll ans=0;
  for(int i=0;i<16;i++) ans=max(ans,dp[h-1][i]);
  cout<<ans<<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[20000][4];
int DP[20000][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][0],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][0],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][0],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][0],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][0],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;
}

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+=2){
			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;
			}
		}
	}
	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 <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

std::vector<std::vector<int>> dp;
std::vector<std::string> s;
std::vector<int> vec;
int h, n;

bool check(int i, int j){
	if(s[i][j] == '#') return false;
	if(s[i + 1][j] == '#') return false;
	if(s[i][j + 1] == '#') return false;
	if(s[i + 1][j + 1] == '#') return false;
	return true;
}

int dfs(int p, int q){
	if(p >= h - 1) return 0;
	if(~dp[p][q]) return dp[p][q];
	
	int ret = 0;
	if(q == 0){
		ret = std::max({dfs(p + 1, 0), dfs(p + 1, 1), dfs(p + 1, 2), dfs(p + 1, 3), dfs(p + 1, 4)});
	}else if(q == 1){
		int count = check(p, 0);
		ret = std::max(count + dfs(p + 1, 2), count + dfs(p + 1, 0));
	}else if(q == 2){
		int count = check(p, 1);
		ret = count + dfs(p + 1, 0);
	}else if(q == 3){
		int count = check(p, 2);
		ret = std::max(count + dfs(p + 1, 0), count + dfs(p + 1, 0));
	}else if(q == 4){
		int count = check(p, 0) + check(p, 2);
		ret = count + dfs(p + 1, 0);
	}
	
	return dp[p][q] = ret;
}

int main(){
	cin >> h >> n; s.resize(h, std::string(4, '.'));
	for(int i = 0; i < n; i++){
		int a, b; cin >> a >> b;
		
		s[b][a] = '#';
	}
	reverse(begin(s), end(s));
	dp.resize(h - 1, std::vector<int>(5, -1));
	
	cout << std::max({dfs(0, 0), dfs(0, 1), dfs(0, 2), dfs(0, 3), dfs(0, 4)}) << endl;
	return 0;
}