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

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

C++: #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define FOR(i,n,a) for(int i = a;i<n;i++)
#define rep(i,n) FOR(i,n,0)
#define UNFOR(i,n,a) for(int i = a;i>n;i--)
#define unrep(i,n) UNFOR(i,0.n)
typedef long long ll;
using namespace std;
bool m[10000][4];
int main() {
	int H, N;
	cin >> H >> N;
	rep(i, N) {
		int a, b;
		cin >> a >> b;
		m[b][a] = true;
	}
	int count = 0;
	rep(i, H-1) {
		if (m[i][0] + m[i][1] + m[i + 1][0] + m[i + 1][1] == 0) {
			count++;
			m[i][0] = m[i][1] = m[i + 1][0] = m[i + 1][1] = true;
		}
	}
	rep(i, H - 1) {
		if (m[i][2] + m[i][3] + m[i + 1][2] + m[i + 1][3] == 0) {
			count++;
			m[i][2] = m[i][3] = m[i + 1][2] = m[i + 1][3] = true;
		}
	}
	rep(i, H - 1) {
		if (m[i][2] + m[i][1] + m[i + 1][2] + m[i + 1][1] == 0) {
			count++;
			m[i][2] = m[i][1] = m[i + 1][2] = m[i + 1][1] = true;
		}
	}
	cout << count << endl;
	cin >> count;
	return 0;
}