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 <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, n;
    cin >> h >> n;
    vector<int> v(h);
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        v[y] |= (1 << x);
    }
    auto dp = make_v<int>(h + 1, 1 << 4, 1 << 4);
    fill_v(dp, -INF);
    dp[0][0][0] = 0;
    for (int i = 1; i < h; i++) {
        for (int j = 0; j < (1 << 4); j++) {
            for (int k = 0; k < (1 << 4); k++) {
                chmax(dp[i][k][0], dp[i - 1][j][k]);
                for (int l = 0; l < 3; l++) {
                    if (((j | k | v[i] | v[i - 1]) & (1 << l)) ||
                        ((j | k | v[i] | v[i - 1]) & (1 << (l + 1)))) {
                        continue;
                    }
                    chmax(dp[i][k | (1 << l) | (1 << (l + 1))][0],
                          dp[i - 1][j][k] + 1);
                }
                if (j == 0 && k == 0 && v[i] == 0 && v[i - 1] == 0) {
                    chmax(dp[i][(1 << 4) - 1][0], dp[i - 1][j][k] + 2);
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < (1 << 4); i++) {
        for (int j = 0; j < (1 << 4); j++) {
            chmax(ans, dp[h - 1][i][j]);
        }
    }
    cout << ans << endl;
}

C++: #include <bits/stdc++.h>
#define put(n) cout<<(n)<<endl
#define FOR(i,num,N) for(int(i)=(num);(i)<(N);++(i))
#define RFOR(i,num,N) for(int (i)=(num);(i)>(N);--(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()
using namespace std;

int main(){
    int H,N,F[10100];
    cin>>H>>N;
    long long dp[10100][1<<4],ans;

    FOR(i,0,N){
        int x,y; cin>>x>>y;
        F[y] |= (1<<x);
    }

    FOR(i,0,10100){
        FOR(j,0,(1<<4)){
            dp[i][j] = -1e9;
        }
    }

    dp[0][F[0]] = 0;

    FOR(i,0,H-1){
        FOR(state,0,(1<<4)){
            FOR(bit,0,(1<<3)){
                int next = F[i+1],cnt=0,ok=1;
                FOR(j,0,3){
                    if(!(bit&(1<<j))) continue;
                    if(state&(3<<j)) ok = 0;
                    if(next&(3<<j)) ok = 0;
                    next |= (3<<j);
                    ++cnt;
                }
                if(!ok) continue;
                dp[i+1][next] = max(dp[i+1][next],dp[i][state]+cnt);
            }
        }
    }
    FOR(i,0,(1<<4)) ans = max(ans,dp[H-1][i]);
    put(ans);
}

C++: 
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

LL H, N;

LL dp[12345][1 << 3];
bool cell[4][12345] = {};

int main(void)
{
	cin >> H >> N;
	for (int i = 0; i < N; ++i)
	{
		int x, y;
		cin >> x >> y;
		cell[x][y] = true;
	}
	for (int i = 0; i < 4; ++i)cell[i][H] = true;
	for (int X = 0; X <= H + 114; ++X)
	{
		for (int i = 0; i < (1 << 3); ++i)
		{
			dp[X][i] = -114514810;
		}
	}
	dp[0][0] = 0;
	for (int i = 1; i <= H; ++i)
	{
		for (int S = 0; S < (1 << 3); ++S)
		{
			for (int T = 0; T < (1 << 3); ++T)
			{
				bool tmp[4][2] = {};
				for (int j = 0; j < 4; ++j)
				{
					tmp[j][0] = cell[j][i - 1];
					tmp[j][1] = cell[j][i];
				}
				int cost = 0;
				if (S & (1 << 0))
				{
					++cost;
					if (tmp[0][0] || tmp[0][1] || tmp[1][0] || tmp[1][1])
					{
						//??????
						continue;
					}
					tmp[0][0] = tmp[0][1] = tmp[1][0] = tmp[1][1] = true;
				}
				if (S & (1 << 1))
				{
					++cost;
					if (tmp[1][0] || tmp[1][1] || tmp[2][0] || tmp[2][1])
					{
						//??????
						continue;
					}
					tmp[1][0] = tmp[1][1] = tmp[2][0] = tmp[2][1] = true;
				}
				if (S & (1 << 2))
				{
					++cost;
					if (tmp[2][0] || tmp[2][1] || tmp[3][0] || tmp[3][1])
					{
						//??????
						continue;
					}
					tmp[2][0] = tmp[2][1] = tmp[3][0] = tmp[3][1] = true;
				}
				if (T & (1 << 0))
				{
					if (tmp[0][0] || tmp[1][0])
					{
						//??????
						continue;
					}
					tmp[0][0] = tmp[1][0] = true;
				}
				if (T & (1 << 1))
				{
					if (tmp[1][0] || tmp[2][0])
					{
						//??????
						continue;
					}
					tmp[1][0] = tmp[2][0] = true;
				}
				if (T & (1 << 2))
				{
					if (tmp[2][0] || tmp[3][0])
					{
						//??????
						continue;
					}
					tmp[2][0] = tmp[3][0] = true;
				}
				dp[i][S] = max(dp[i][S], dp[i - 1][T] + cost);
			}
		}
	}
	cout << dp[H][0] << endl;
	return 0;
}

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(i+1+j < h && 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;
}