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 <iostream>
using namespace std;
typedef long long ll;

ll h, n;
bool room[10004][4];
ll cnt[10004];

bool putable(ll sx, ll sy) {
    return !(room[sy][sx] || room[sy + 1][sx] || room[sy][sx + 1] || room[sy + 1][sx + 1]);
}

void put(ll sx, ll sy) {
    room[sy][sx] = room[sy][sx + 1] = room[sy + 1][sx] = room[sy + 1][sx + 1] = true;
}

int main() {
    cin >> h >> n;
    for (int i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        room[y][x] = true;
    }
    room[h][0] = room[h][1] = room[h][2] = room[h][3] = true;

    for (int i = h - 1; i >= 0; i--) {
        if (!(room[i][0] || room[i][1] || room[i][2] || room[i][3])) cnt[i] = cnt[i + 1] + 1;
        else cnt[i] = 0;
    }
    

    ll ans = 0;

    for (int i = 0; i < h; i++) {
        if (putable(0, i)) {
            put(0, i);
            ans++;
        }
        if (putable(2, i)) {
            put(2, i);
            ans++;
        }
        if (putable(1, i)) {
            if (cnt[i + 1] % 2 == 1 || cnt[i + 1] == 0) {
                put(1, i);
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

C++: /*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

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

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1LL,0,1LL,0 }, dy[] = { 0,1LL,0,-1LL };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; }for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

bool bd[10005][4];
int dp[10005][5];

signed main() {
	int h,n;
	cin >> h >> n;
	REP (i,10005) {
		REP (j,4) {
			bd[i][j] = true;
		}
	}
	REP (i,n) {
		int x,y;
		cin >> x >> y;
		bd[y][x] = false;
	}
	FOR (i,1,h) {
		if (bd[i-1][0] && bd[i-1][1] && bd[i-1][2] && bd[i-1][3] &&
			  bd[i][0] &&   bd[i][1] &&   bd[i][2] &&   bd[i][3]) {
			dp[i][3] = max(dp[i][3],dp[i-1][0]+2);
		}
		if (bd[i-1][0] && bd[i-1][1] &&
			  bd[i][0] &&   bd[i][1]) {
			dp[i][1] = max(dp[i][1],max(dp[i-1][0],dp[i-1][2])+1);
		}
		if (bd[i-1][2] && bd[i-1][3] &&
			  bd[i][2] &&   bd[i][3]) {
			dp[i][2] = max(dp[i][2],max(dp[i-1][0],dp[i-1][1])+1);
		}
		if (bd[i-1][1] && bd[i-1][2] &&
			  bd[i][1] &&   bd[i][2]) {
			dp[i][4] = max(dp[i][4],dp[i-1][0]+1);
		}
		dp[i][0] = max({dp[i-1][0],dp[i-1][1],dp[i-1][2],dp[i-1][3],dp[i-1][4]});
	}
	int ans = 0;
	REP (i,5) {
		ans = max(ans,dp[h-1][i]);
	}
	cout << ans << endl;
}

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

#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()

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

    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] = -1;
        }
    }

    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 <bits/stdc++.h>

using namespace std;

#define int long long
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int H, N;
int located[100000];
int dp[2][1 << 4];
int down[5] = {0b0000, 0b0011, 0b0110, 0b1100, 0b1111};
int score[5] = {0, 1, 1, 1, 2};
signed main() {
	cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> H >> N;
    for(int i = 0; i < N; ++i) {
        int x, y;
        cin >> x >> y;
        located[y] |= 1 << x;
    }
    int *now = dp[0];
    int *next = dp[1];
    for(int i = 0; i < (1 << 4); ++i) {
        if(i & located[0]) now[i] = -1;
        else now[i] = 0;
    }
    for(int i = 0; i < H - 1; ++i) {
        fill(next, next + (1 << 4), -1);
        for(int j = 0; j < (1 << 4); ++j) {
            if(now[j] == -1) continue;
            for(int k = 0; k < 5; ++k) {
                int front = down[k] & located[i];
                int back = down[k] & located[i + 1];
                if(front || back || j & located[i]) continue;
                int next_put = down[k] | located[i];
                next[next_put] = max(next[next_put], now[j] + score[k]);
            }
        }
        int *temp = now;
        now = next;
        next = temp;
    }
    int res = 0;
    for(int i = 0; i < (1 << 4); ++i) chmax(res, next[i]);
    cout << res << endl;
	return 0;
}