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

C++: #include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ユニークなvectorにする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

int h, n;
vector<int> b;

int dp[10000][8];

int dfs(int i = 1, int bit = 0) {
  if (i == h) { // 最後まで来た場合
    return 0;
  }
  bit |= b[i]; // 置ける状況を取得

  int &ret = dp[i][bit]; // おける最大数、配列の中身を変えたいので参照取得
  if (~ret)
    return ret;  // 計算済みなら返す  retが-1だと~retは0となり計算するために次へ

  ret = 0;
  if (bit == 0) // 2つ置く場合
    ret = max(ret, dfs(i + 1, 0b111) + 2);
  if ((bit & (0b100)) == 0) // 左に置く場合
    ret = max(ret, dfs(i + 1, 0b110) + 1);
  if ((bit & (0b010)) == 0) // 中に置く場合
    ret = max(ret, dfs(i + 1, 0b111) + 1);
  if ((bit & (0b001)) == 0) // 右に置く場合
    ret = max(ret, dfs(i + 1, 0b011) + 1);
  ret = max(ret, dfs(i + 1, 0)); // 置かない場合

  // 5パターンの最大値がretに
  return ret;
}

int main() {
  memset(dp, -1, sizeof(dp));
  cin >> h >> n;

  // eiはそれぞれ x の値に対応するおけない箇所
  int ei[4] = {0b100, 0b110, 0b011, 0b001};
  b.assign(h + 1, 0);
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    // 置けなくなる箇所をパターンとして用意
    b[y + 1] |= ei[x];
    b[y] |= ei[x];
  }

  cout << dfs() << endl;
}

C++: #include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

UL H, N;
UL dp[40000][16] = {};
UL G[40000] = {};

int main() {
	cin >> H >> N;
	rep(i, N) {
		UL x, y; cin >> x >> y;
		G[y] |= (1 << x);
	}
	rep(y, H - 1) {
		for (pair<UL, UL> g : {
			make_pair(0b0000, 0),
			make_pair(0b1100, 1),
			make_pair(0b0110, 1),
			make_pair(0b0011, 1),
			make_pair(0b1111, 2)
			}) {
			if (G[y] & g.first) continue;
			if (G[y + 1] & g.first) continue;
			rep(i, 16) {
				if (i & g.first) continue;
				dp[y + 1][g.first] = max(dp[y + 1][g.first], dp[y][i] + g.second);
			}
		}
	}
	UL ans = 0;
	rep(i, 16) ans = max(ans, dp[H - 1][i]);
	cout << ans << endl;
	return 0;
}

C++: #include <stdio.h>
#define MAX_H 100000
int blocked[MAX_H];
int dp[2][1<<4];

main() {
 int h, n; scanf("%d %d", &h, &n);
 int x, y;
 for ( int i=0; i<n; ++i ) {
  scanf("%d %d", &x, &y); blocked[y] |= 1<<x;
 }
 int locate[5] = { 0x0, 0x3, 0x6, 0xc, 0xf };//置き方パターン
 int add[5] = { 0, 1, 1, 1, 2 };//各置き方パターンで置ける個数

 int* crt = dp[0];
 int* next = dp[1];

 for ( int obstacle=0; obstacle<1<<4; ++obstacle ) {
if ( obstacle&blocked[0] ) crt[obstacle] = -1;
else crt[obstacle] = 0;
 }

 for ( int i=0; i<h-1; ++i ) {
  std::fill( next, next+(1<<4), -1 );
   for ( int obstacle=0; obstacle<1<<4; ++obstacle ) { //既に有るものパターン(current)
     if ( crt[obstacle] == -1 ) continue;
     for ( int k=0; k<5; ++k ) { //置き方パターン(next)
      int check0 = blocked[i] & locate[k];
      int check1 = blocked[i+1] & locate[k];
     if ( !check0 && !check1 && !(obstacle&locate[k])) {
      int patt = blocked[i+1] | locate[k];
      next[patt] = std::max( crt[obstacle] + add[k], next[patt] );
   }
  }
}
int* tmp = crt;
crt = next;
next = tmp;
 }
 int res = 0;
 for ( int i=0; i<1<<4; ++i ) if ( next[i] > res ) res = next[i];
 printf("%d¥n", res );
}

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::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int h, n; scanf("%d%d", &h, &n);

	std::vector<std::string> s(h, std::string(4, '.'));
	while(n--) {
		int x, y; scanf("%d%d", &x, &y);

		s[y][x] = '#';
	}

	auto put = [](std::vector<std::string> s, int y) {
		std::pair<int, std::string> p = {0, s[1]};
		if(s[0][y] == '.' and s[0][y + 1] == '.' and s[1][y] == '.' and s[1][y + 1] == '.') p.first = 1;
		p.second[y] = p.second[y + 1] = '#';
		return p;
	};

	std::vector<std::map<std::string, int>> dp(h + 1); dp[1][s[0]] = 0;
	for(int i = 1; i < h; i++) {
		for(auto from: dp[i]) {
			std::vector<std::string> t = {from.first, s[i]};
			int val = from.second;

			auto A = put(t, 0);
			auto B = put(t, 1);
			auto C = put(t, 2);
			auto D = put(std::vector<std::string>{from.first, A.second}, 2);
			dp[i + 1][s[i]] = std::max(dp[i + 1][s[i]], val);
			if(A.first) dp[i + 1][A.second] = std::max(dp[i + 1][A.second], val + 1);
			if(B.first) dp[i + 1][B.second] = std::max(dp[i + 1][B.second], val + 1);
			if(C.first) dp[i + 1][C.second] = std::max(dp[i + 1][C.second], val + 1);
			if(A.first and C.first) dp[i + 1][D.second] = std::max(dp[i + 1][D.second], val + 2);
		}
	}
	int ans = 0;
	for(auto v: dp[h]) ans = std::max(ans, v.second);
	printf("%d\n", ans);
	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 H,N,F[10100];
long long dp[10100][1<<4];

int main(){
    cin>>H>>N;

    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);
            }
        }
    }
    long long ans = -2;
    FOR(i,0,(1<<4)) ans = max(ans,dp[H-1][i]);
    put(ans);
}