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;

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]) {
      if(!(i < (h - 2) && !s[0][i + 1] && !s[1][i + 1] && !s[0][i + 2] && !s[1][i + 2] && !s[2][i + 1] && !s[3][i + 1] && !s[2][i + 2] && !s[3][i + 2])) {
        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 <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> 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 1e9+7

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

int main() {
  int h, n, ans = 0;
  cin >> h >> n;
  int m[4][h];
  rep(i, 0, 4) rep(j, 0, h) m[i][j] = 0;
  rep(i, 0, n) {
    int x, y;
    cin >> x >> y;
    m[x][y] = 1;
  }

  rep(i, 0, h - 1) {
    if(!m[0][i] && !m[1][i] && !m[0][i + 1] && !m[1][i + 1]) {
      m[0][i] = 1, m[1][i] = 1, m[0][i + 1] = 1, m[1][i + 1] = 1;
      ans++;
    }
    if(!m[2][i] && !m[3][i] && !m[2][i + 1] && !m[3][i + 1]) {
      m[2][i] = 1, m[3][i] = 1, m[2][i + 1] = 1, m[3][i + 1] = 1;
      ans++;
    }
    if(!m[1][i] && !m[2][i] && !m[1][i + 1] && !m[2][i + 1]) {
      int k = 0;
      while(!m[0][i + 1 + k] && !m[1][i + 1 + k] && !m[2][i + 1 + k] && !m[3][i + 1 + k]) {
        k++;
      }
      if(!k || k % 2 == 1) {
        m[1][i] = 1, m[2][i] = 1, m[1][i + 1] = 1, m[2][i + 1] = 1;
        ans++;
      }
    }
  }

  cout << ans << endl;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

int N, K, A[4][10009], dp[10009][16];

int main() {
	cin >> N >> K;
	for (int i = 0; i < K; i++) {
		int p, q; scanf("%d%d", &p, &q);
		A[p][q] = 1;
	}
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= 15; j++) dp[i][j] = -(1 << 30);
	}
	dp[0][0] = 0;
	for (int i = 0; i < N - 1; i++) {
		for (int j = 0; j <= 15; j++) {
			if (dp[i][j] < 0) continue;

			dp[i + 1][0] = max(dp[i + 1][0], dp[i][j]);
			for (int cl = 0; cl <= 3; cl++) {
				for (int cr = cl + 1; cr <= 3; cr += 2) {
					// [cl, cr] に置く
					bool flag = true;
					for (int k = cl; k <= cr; k++) {
						if (A[k][i] == 1 || A[k][i + 1] == 1 || (j / (1 << k)) % 2 == 1) flag = false;
					}
					if (flag == false) continue;

					int sum = 0;
					for (int k = cl; k <= cr; k++) sum += (1 << k);
					dp[i + 1][sum] = max(dp[i + 1][sum], dp[i][j] + (cr - cl + 1) / 2);
				}
			}
		}
	}

	int maxn = 0;
	for (int i = 0; i <= 15; i++) maxn = max(maxn, dp[N - 1][i]);
	cout << maxn << endl;
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int h, n;
    cin >> h >> n;
    vector<int> grid(h, 15);
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        grid[y] ^= (1 << x);
    }
    vector<array<int, 16>> dp(h);
    for (auto &&i : dp) fill(i.begin(),i.end(), -INF<int>);
    dp[0][grid[0]] = 0;
    for (int i = 1; i < h; ++i) {
        for (int S = 0; S < 16; ++S) {
            if(dp[i-1][S] < 0) continue;
            for (int T = grid[i]; ; T = grid[i]&(T-1)) {
                chmax(dp[i][T], dp[i-1][S]);
                if((S&3) == 3 && (T&3) == 3) chmax(dp[i][T^3], dp[i-1][S]+1);
                if((S&6) == 6 && (T&6) == 6) chmax(dp[i][T^6], dp[i-1][S]+1);
                if((S&12) == 12 && (T&12) == 12) chmax(dp[i][T^12], dp[i-1][S]+1);
                if((S&15) == 15 && (T&15) == 15) chmax(dp[i][T^15], dp[i-1][S]+2);
                if(!T) break;
            }
        }
    }
    cout << *max_element(dp.back().begin(),dp.back().end()) << "\n";
    return 0;
}

C++: #include<iostream>
#include<algorithm>
bool m[4][10010];
int dp[100010];
int main(){
	int H, N;
	std::cin >> H >> N;
	for(int i = 0; i < N; i++){
		int x, y;
		std::cin >> x >> y;
		m[x][y] = true;
	}
	for(int i = 0; i < H - 1; i++){
		dp[i + 1] = std::max(dp[i], dp[i + 1]);
		int res1 = 0;
		if((!m[0][i]) && (!m[1][i]) && (!m[0][i + 1]) && (!m[1][i + 1]))res1++;
		if((!m[2][i]) && (!m[3][i]) && (!m[2][i + 1]) && (!m[3][i + 1]))res1++;
		int res2 = 0;
		if((!m[1][i]) && (!m[2][i]) && (!m[1][i + 1]) && (!m[2][i + 1]))res2++;
		dp[i] += std::max(res1, res2);
		dp[i + 2] = std::max(dp[i], dp[i + 2]);
	}
	std::cout << std::max(dp[H - 1], dp[H - 2]) <<std::endl;
	return 0;
}