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>
using namespace std;

int obs[10005];
int dp[10005][16];
int mask[5]={0, 3, 6, 12, 15};
int cnt[5] ={0, 1, 1, 1,  2};
int main() {
  int h, n;
  cin >> h >> n;
  fill(obs, obs+10005, 0);
  for(int i=0; i<n; i++){
    int x, y;
    cin >> x >> y;
    obs[y]=obs[y] | (1<<x);
  }
  obs[h]=15;
  fill(dp[h], dp[h]+16, 0);
  for(int i=h-1; i>=0; i--){
    for(int j=0; j<16; j++){
      dp[i][j]=0;
      for(int k=0; k<5; k++){
        if((mask[k]&j)|(mask[k]&obs[i+1])) continue;
        dp[i][j]=max(dp[i][j], 
             cnt[k]+dp[i+1][obs[i+1]|mask[k]]);
      }
    }
  }
  cout << dp[0][obs[0]] << endl;
}

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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll h, n, cnt = 0;
  bool s[4][10001];
  cin >> h >> n;
  ll x, y;
  rep(i, n) {
    cin >> x >> y;
    s[x][h - (y + 1)] = true;
  }
  
  rep(i, h - 1) {
    if(!s[0][i] && !s[1][i] && !s[0][i + 1] && !s[1][i + 1]) {
      s[0][i] = s[1][i] = s[0][i + 1] = s[1][i + 1] = true;
      cnt++;
    }
    if(!s[2][i] && !s[3][i] && !s[2][i + 1] && !s[3][i + 1]) {
      s[2][i] = s[3][i] = s[2][i + 1] = s[3][i + 1] = true;
      cnt++;
    }
    if(!s[1][i] && !s[2][i] && !s[1][i + 1] && !s[2][i + 1]) {
      s[1][i] = s[2][i] = s[1][i + 1] = s[2][i + 1] = true;
      cnt++;
    }
  }
  /*
  rep(i, h) {
    rep(j, 4) {
      if(s[j][i]) {
        cout << '#';
      } else cout << '.';
    }
    cout << endl;
  }
  */
  cout << cnt << endl;
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define RREP(i,n) RFOR(i,0,n)

const int _N = 3e5 + 100;
int bitcount[] = {0,1,1,2,1,2,2,3};

int h,n;
bool b[4][10000];
int dp[2][1<<3];

int main(){
	cin >> h >> n;
	REP(i, n){
		int x,y;
		cin >> x >> y;
		b[x][y] = true;
	}
	REP(y, h-1){
		int *prev = dp[0];
		int *now = dp[1];
		REP(i, 1 << 3){
			now[i] = 0;
			REP(j, 1 << 3){
				bool flag = false;

				// check i(y) height block
				REP(x, 3)REP(dx, 2)REP(dy, 2)
					if((i & (1 << x)) && b[x + dx][y + dy])
						flag = true;

				// check j(y-1) height block
				if(y>=1)REP(x, 3)REP(dx, 2)REP(dy, 2)
					if((j & (1 << x)) && b[x + dx][y - 1 + dy])
						flag = true;

				// check hit i and j
				REP(x, 2)REP(dxi, 2)REP(dxj, 2)
					if((i & (1 << (x + dxi))) && (j & (1 << (x + dxj))))
						flag = true;

				// check in only i and in only j
				REP(x, 2)if((i & (1 << (x + 1))) && (i & (1 << x)))
					flag = true;
				REP(x, 2)if((j & (1 << x)) && (j & (1 << (x + 1))))
					flag = true;

				if(flag)continue;
				now[i] = max(now[i], prev[j] + bitcount[i]);
			}
		}
		swap(dp[0], dp[1]);
	}
	int ans = 0;
	REP(i, 1<<3)
		ans = max(ans, dp[0][i]);
	cout << ans << endl;
}

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){ //xxxx
		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){ //ooxx
		int count = check(p, 0);
		ret = std::max(count + dfs(p + 1, 2), count + dfs(p + 1, 0));
	}else if(q == 2){ //xoox
		int count = check(p, 1);
		ret = count + dfs(p + 1, 0);
	}else if(q == 3){ //xxoo
		int count = check(p, 2);
		ret = std::max(count + dfs(p + 1, 0), count + dfs(p + 1, 1));
	}else if(q == 4){ //oooo
		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;
}

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

int c[50000][4]{};

bool check(int i, int j) {
    for (int k = 0; k < 4; k++) {
        int t = 1<<k;
        if ((t & j) != 0 && c[i][k] == 1) return false;
    }
    return true;
}

int main() {
    int H, N;
    cin >> H >> N;
    int x[N], y[N];
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
        c[y[i]][x[i]] = 1;
    }

    int d[H][16]{};
    fill(d[0], d[H], -1);
    int a = 0;
    
    for (int i = 0; i < 4; i++) {
        if (c[0][i] == 1) a += (1<<i);
    }
    d[0][a] = 0;
    
    // 0000 1100 0110 0011 1111
    // 0    3    6    12    15
    for (int i = 1; i < H; i++) {
        int t = 0; // i-1 列目の配置
        int u = 0; // i列目の配置
        for (int j = 0; j < 4; j++) {
            if (c[i - 1][j] == 1) t += (1<<j);
            if (c[i][j] == 1) u += (1<<j);
        }
        // 何も置かない
        for (int j = 0; j < 16; j++) {
            d[i][u] = max(d[i][u], d[i - 1][j]);
        }
        
        for (int j = 0; j < 16; j++) {
            if (d[i - 1][j] < 0) continue;
            for (int k = 0; k < 3; k++) {
                int c = (1<<k) + (1<<(k + 1));
                if (check(i - 1, c) && check(i, c) && (j & c) == 0) {
                    d[i][u | c] = max(d[i][u | c], d[i - 1][j] + 1);
                }
            }
            if (check(i, 15) && check(i - 1, 15) && (j & 15) == 0) {
                d[i][15] = max(d[i][15], d[i - 1][j] + 2);
            }
        }
    }
    int v = 0;
    for (int i = 0; i < 16; i++) {
        v = max(v, d[H - 1][i]);
    }
    cout << v << "\n";
    
    return 0;
}