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 < H-1; i++ {
		for j := 0; j < 3; j++ {
			if !room[i][j] && !room[i+1][j] && !room[i][j+1] && !room[i+1][j+1] {
				room[i][j] = true
				room[i+1][j] = true
				room[i][j+1] = true
				room[i+1][j+1] = true
				count++
			}
		}
	}
	fmt.Println(count)
}

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

i64 h, n;
vector<i64> obj;
vector<vector<i64>> dp;

i64 dfs(i64 hn, i64 s)
{
  if (hn == h)
    return 0;
  if (dp[hn][s] != -1)
    return dp[hn][s];
  i64 ans = dfs(hn + 1, obj[hn]);
  for (i64 i = 0; i < 3; i++)
  {
    if (((s >> i) & 3) || ((obj[hn] >> i) & 3))
      continue;
    ans = max(ans, dfs(hn + 1, obj[hn] | (3 << i)) + 1);
  }
  if (s == 0 && obj[hn] == 0)
    ans = max(ans, dfs(hn + 1, (1 << 4) - 1) + 2);
  return dp[hn][s] = ans;
}

int main()
{
  cin >> h >> n;
  obj.resize(h);
  for (i64 i = 0; i < n; i++)
  {
    i64 x, y;
    cin >> x >> y;
    obj[y] |= (1 << x);
  }
  dp.resize(h, vector<i64>(16, -1));
  cout << dfs(1, obj[0]) << endl;
  return 0;
}

C++: #include <stdio.h>
int main(void) {
   int H,N,i,j,p[4][10002],x,y,c;
   for(i=0;i<10002;i++){
	   p[0][i]=0;p[1][i]=0;p[2][i]=0;p[3][i]=0;
   }
   scanf("%d %d",&H,&N);
   for(i=0;i<N;i++){
	   scanf("%d %d",&x,&y);
	   p[x][y]=9;
   }
  for(i=H;i<10002;i++){
	   p[0][i]=9;p[1][i]=9;p[2][i]=9;p[3][i]=9;
  }
  c=0;
  j=1;
	  for(i=1;i<H;i++){
		  if(p[j][i]==0&&p[j-1][i-1]==0&&p[j-1][i]==0&&p[j][i-1]==0){
			  p[j][i]=1;p[j-1][i]=1;p[j][i-1]=1;p[j-1][i-1]=1;
			  c++;
		  }
	  }
  j=3;
	  for(i=1;i<H;i++){
		  if(p[j][i]==0&&p[j-1][i-1]==0&&p[j-1][i]==0&&p[j][i-1]==0){
			  p[j][i]=1;p[j-1][i]=1;p[j][i-1]=1;p[j-1][i-1]=1;
			  c++;
		  }
	  }
  j=2;
	  for(i=1;i<H;i++){
		  if(p[j][i]==0&&p[j-1][i-1]==0&&p[j-1][i]==0&&p[j][i-1]==0){
			  p[j][i]=1;p[j-1][i]=1;p[j][i-1]=1;p[j-1][i-1]=1;
			  c++;
		  }
	  }

  for(i=0;i<H;i++){
	  printf("%d%d%d%d\n",p[0][i],p[1][i],p[2][i],p[3][i]);
  }

  printf("%d\n",c);
   return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<random>
#include<math.h>
#include<limits.h>
#include<iterator>
#include<queue>
#include<functional>
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
#define ll long long
#define vl vector<ll> 
#define vvl vector<vector<ll> > 
#define vb vector<bool> 
#define vvb vector<vector<bool> > 
#define INF 11234567890123456789
using namespace std;

int main(){
	ll h, n; cin >> h >> n;
	vvb map(4, vb(h, true));
	vvb map_b(3, vb(h, false));
	rep(i, n){
		ll x, y; cin >> x >> y;
		map[x][y] = false;
	}
	vl dp(h, 0);
	ll count = 0;
	rep(i, h-1){
		ll plus = 0;
		if (i > 0) plus = dp[i - 1];
		rep(j, 3){
			if (map[j][i] && map[j][i + 1] && map[j + 1][i] && map[j + 1][i + 1]){
				map_b[j][i] = true;
			}
		}
		if (map_b[0][i] && map_b[2][i]) dp[i + 1] = 2 + plus;
		else if (map_b[0][i] || map_b[1][i] || map_b[2][i]){
			if (i > 0){
				if ((map_b[0][i-1] && map_b[2][i]) || (map_b[2][i-1] && map_b[0][i])) dp[i + 1] = 2 + plus;
				else dp[i + 1] = 1 + plus;
			}else dp[i + 1] = 1 + plus;
		}
		else dp[i + 1] = plus;
		dp[i + 1] = max(dp[i], dp[i + 1]);
	}cout << dp[h - 1] << endl;
	return 0;
}

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;

    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;

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

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

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

signed main() {
  int h, n;
  cin >> h >> n;

  bool t[4][10005] = {};

  rep(i, 0, n) {
    int x, y;
    cin >> x >> y;
    t[x][y] = true;
  }
  int ans = 0;
  rep(i, 0, h - 1) {
    if(!t[0][i] && !t[1][i] && !t[0][i + 1] && !t[1][i + 1]) {
      ans++, t[1][i] = true, t[0][i + 1] = true, t[1][i + 1] = true;
    }
    if(!t[2][i] && !t[3][i] && !t[2][i + 1] && !t[3][i + 1]) {
      ans++, t[2][i] = true, t[2][i + 1] = true, t[3][i + 1] = true;
    }
    if(!t[1][i] && !t[2][i] && !t[1][i + 1] && !t[2][i + 1]) {
      int k = 0;
      while(!t[0][i + 1 + k] && !t[1][i + 1 + k] && !t[2][i + 1 + k] && !t[3][i + 1 + k] && i + k < h) k++;
      if(k < 2 || k % 2) {
        ans++, t[1][i + 1] = true, t[2][i + 1] = true;
      }
    }
  }
  cout << ans << endl;
}