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>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int h, m; cin >> h >> m;
	vi bit(h);
	rep(i, m){
		int x, y; cin >> x >> y;
		bit[y] |= 1 << x;
	}
	vector<vi> dp(2, vi(1 << 4, -1));
	dp[0][bit[0]] = 0;
	
	int cur = 0, next = 1;
	rep(i, h - 1){
		fill(all(dp[next]), -1);
		rep(j, 1 << 4) if(dp[cur][j] >= 0){
			int nj = bit[i + 1];
			dp[next][nj] = max(dp[next][nj], dp[cur][j]);
			if(((j | nj) & 3) == 0){//0,1
				dp[next][nj | 3] = max(dp[next][nj | 3], dp[cur][j] + 1);
			}
			if(((j | nj) >> 1 & 3) == 0){//1,2
				dp[next][nj | 6] = max(dp[next][nj | 6], dp[cur][j] + 1);
			}
			if((j | nj) >> 2 == 0){//2,3
				dp[next][nj | 12] = max(dp[next][nj | 12], dp[cur][j] + 1);
			}
			if(j == 0 && nj == 0){//0-3
				dp[next][15] = max(dp[next][15], dp[cur][j] + 2);
			}
		}
		swap(cur, next);
	}
	cout << *max_element(all(dp[cur])) << endl;
	
	return 0;
}

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

using ll = long long;
using pii = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;

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

    vector<vector<int>> dp(H + 1, vector<int>(1 << 4));
    for(int i = 0; i < H; ++i) {
        int no_put = 0;
        for(int S = 0; S < (1 << 4); ++S) {
            if((state[i] & S) != state[i]) continue;
            no_put = max(no_put, dp[i][S]);

            if(S == 0 && state[i + 1] == 0) { // put two
                dp[i + 1][0b1111] = max(dp[i + 1][0b1111], dp[i][S] + 2);
            }

            for(int j = 0; j < 3; ++j) { // put one
                if((S & (0b0011 << j)) == 0 && (state[i + 1] & (0b0011 << j)) == 0) {
                    int nS = state[i + 1] | (0b0011 << j);
                    dp[i + 1][nS] = max(dp[i + 1][nS], dp[i][S] + 1);
                }
            }
        }
        dp[i + 1][state[i + 1]] = max(dp[i + 1][state[i + 1]], no_put);
    }

    cout << dp[H].back() << endl;
}

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

int dp[10005][5]; //0 ???????????? 1 ???????????? 2 ?????????????????? 3 ???????????? 4 ?????????????????????

int main() {

    int h,n;

    cin >> h >> n;

    int x,y;

    for(int i=0;i<n;i++) {
        cin >> x >> y;
        if(x==0){
            dp[h-y][0] = dp[h-y-1][0] = dp[h-y][1] = dp[h-y-1][1] = -1;
        }
        else if(x==1){
            dp[h-y][0] = dp[h-y-1][0] = dp[h-y][1] = dp[h-y-1][1] = dp[h-y][2] = dp[h-y-1][2] = -1;
        }
        else if(x==2){
            dp[h-y][0] = dp[h-y-1][0] = dp[h-y][2] = dp[h-y-1][2] = dp[h-y][3] = dp[h-y-1][3] = -1;
        }
        else if(x==3){
            dp[h-y][0] = dp[h-y-1][0] = dp[h-y][3] = dp[h-y-1][3] = -1;
        }
    }
    
    for(int i=1;i<h;i++){
        if(dp[i][0] != -1) {
            dp[i][0] = dp[i - 1][4] + 2;
        }
        if(dp[i][1] != -1) {
            dp[i][1] = max(dp[i - 1][3] + 1, dp[i - 1][4] + 1);
        }
        if(dp[i][2] != -1) {
            dp[i][2] = dp[i - 1][4] + 1;
        }
        if(dp[i][3] != -1) {
            dp[i][3] = max(dp[i - 1][1] + 1, dp[i - 1][4] + 1);
        }
        dp[i][4] = max(max(dp[i - 1][0], dp[i - 1][1]), max(dp[i - 1][2], max(dp[i - 1][3], dp[i - 1][4])));
    }

    cout << max(max(dp[h-1][0],dp[h-1][1]),max(dp[h-1][2],max(dp[h-1][3],dp[h-1][4]))) << endl;
    



    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
bool data[4][10010];
int dp[10010][16];
int main(){
	int h, n;
	cin >> h >> n;
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 10010; j++) data[i][j] = true;
	}
	for(int i = 0; i < 10010; i++){
		for(int j = 0; j < 16; j++) dp[i][j] = -1;
	}
	for(int i = 0; i < n; i++){
		int x, y;
		cin >> x >> y;
		data[x][y] = false;
	}
	int s = 0;
	if(data[0][0]) s = s | 8;
	if(data[1][0]) s = s | 4;
	if(data[2][0]) s = s | 2;
	if(data[3][0]) s = s | 1;
	dp[0][s] = 0;
	for(int i = 0; i < h-1; i++){
		for(int j = 0; j < 16; j++){
			if(dp[i][j] == -1) continue;
			int st = j;
			// cout << data[0][i+1] <<  data[1][i+1] <<  data[2][i+1] <<  data[3][i+1] << endl;	
			if(data[0][i+1]) st = st | 128;
			if(data[1][i+1]) st = st | 64;
			if(data[2][i+1]) st = st | 32;
			if(data[3][i+1]) st = st | 16;
			// cout << i << " " << j << " " << st << endl;
			//none
			{
				int st2 = st >> 4;
				// cout << "none" << endl;
				// cout << j << " -> " << st2 << endl;
				dp[i+1][st2] = max(dp[i+1][st2], dp[i][j]);
			}
			//left
			if((st & 204) == 204){
				int st2 = st >> 4;
				st2 = st2 & 3;
				// cout << "left" << endl;
				// cout << j << " -> " << st2 << endl;
				dp[i+1][st2] = max(dp[i+1][st2], dp[i][j] + 1);
			}
			//middle
			if((st & 102) == 102){
				int st2 = st >> 4;
				st2 = st2 & 9;
				// cout << "middle" << endl;
				// cout << j << " -> " << st2 << endl;
				dp[i+1][st2] = max(dp[i+1][st2], dp[i][j] + 1);
			}
			//right
			if((st & 51) == 51){
				int st2 = st >> 4;
				st2 = st2 & 12;
				// cout << "right" << endl;
				// cout << j << " -> " << st2 << endl;
				dp[i+1][st2] = max(dp[i+1][st2], dp[i][j] + 1);
			}
			//left+right
			if((st & 255) == 255){
				// cout << "left and right" << endl;
				// cout << j << " -> " << 0<< endl;
				dp[i+1][0] = max(dp[i+1][0], dp[i][j] + 2);
			}
			// cout << "----" << endl << endl;
		}
	}
	int ans = 0;
	for(int i = 0; i < 16; i++){
		// cout << dp[h-1][i] << " ";
		ans = max(ans, dp[h-1][i]);
	}
	cout << ans << endl;
}