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>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;

int a[100000], dp[2][1<<5];
int put[] = {0, 3, 6, 12, 15};
int cnt[] = {0, 1, 1, 1, 2};
signed main(){
	int h, n;
	scanf("%lld%lld", &h, &n);
	rep(i,n){
		int x, y;
		scanf("%lld%lld", &x, &y);
		a[y] = (1<<x);
	}
	rep(bit,(1<<4)){
		if(bit == a[0])dp[0][bit] = 0;
		else dp[0][bit] = -1;
	}
	
	rep(i,h-1){
		fill(dp[1], dp[1]+(1<<5), -1);
		rep(bit,(1<<4)){
			if(dp[0][bit] == -1)continue;
			rep(k,5){
				int check1 = a[i]&put[k];
				int check2 = a[i+1]&put[k];
				if(!check1 and !check2 and !(bit&put[k])){
					int b = a[i+1] | put[k];
					dp[1][b] = max(dp[1][b], dp[0][bit]+cnt[k]);
				}
			}
		}
		swap(dp[0], dp[1]);
	}
	
	int ans = 0;
	rep(i,(1<<4))chmax(ans, dp[0][i]);
	printf("%lld\n", ans);
	return 0;
}

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 < h) k++;
      if(k < 2 || k % 2) {
        ans++, t[1][i + 1] = true, t[2][i + 1] = true;
      }
    }
  }
  cout << ans << endl;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define MAX 114514
signed main(){
  int h,n;
  cin>>h>>n;
  int bi[MAX];
  memset(bi,0,sizeof(bi));
  for(int i=0;i<n;i++){
    int x,y;
    cin>>x>>y;
    bi[y]|=1<<x;
  }
  static int dp[1<<8][MAX];
  memset(dp,-1,sizeof(dp));
  int ms=(1<<8)-1;
  auto p=[&](int x){return x&1;};
  function<int(int,int)> dfs=[&](int b,int y){
    //cout<<bitset<8>(b)<<" "<<y<<"+"<<dp[b][y]<<endl;
    if(~dp[b][y]) return dp[b][y];
    if(y+1==h) return 0;
    int res=dfs(((b<<4)+bi[y+2])&ms,y+1);
    if(b==0){
      res=max(res,dfs(((15<<4)+bi[y+2])&ms,y+1)+2);
    }
    if(p(b>>4)==0&&p(b>>5)==0&&p(b>>0)==0&&p(b>>1)==0){
      res=max(res,dfs((((b+3)<<4)+bi[y+2])&ms,y+1)+1);
    }
    if(p(b>>5)==0&&p(b>>6)==0&&p(b>>1)==0&&p(b>>2)==0){
      res=max(res,dfs((((b+6)<<4)+bi[y+2])&ms,y+1)+1);
    }
    if(p(b>>6)==0&&p(b>>7)==0&&p(b>>2)==0&&p(b>>3)==0){
      res=max(res,dfs((((b+12)<<4)+bi[y+2])&ms,y+1)+1);
    }
    //cout<<bitset<8>(b)<<" "<<y<<":"<<res<<endl;
    return dp[b][y]=res;
  };
  cout<<dfs((bi[0]<<4)+bi[1],0)<<endl;
  return 0;
}

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;
}