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>
using namespace std;
bool mp[10005][4];

int main(){
  ios_base::sync_with_stdio(false);
  int h,n,x,y;
  for(int i=0;i<10005;i++){
    for(int j=0;j<4;j++){
      mp[i][j] = true;
    }
  }
  cin >> h >> n;
  
  for(int i=0;i<n;i++){
    cin >> x >> y;
    mp[y][x] = false;
  }

  int ans = 0;
  for(int i=0;i<h-1;i++){
    if(mp[i][0] && mp[i][1] && mp[i+1][0] && mp[i+1][1]){ //左に正方形が作れるとき
      mp[i][0] = mp[i][1] = mp[i+1][0] = mp[i+1][1] = false;
      ans++;
    }
    if(mp[i][2] && mp[i][3] && mp[i+1][2] && mp[i+1][3]){ //右に正方形が作れるとき
      mp[i][2] = mp[i][3] = mp[i+1][2] = mp[i+1][3] = false;
      ans++;
    }
    if(mp[i][1] && mp[i][2] && mp[i+1][1] && mp[i+1][2]){ //真ん中に正方形が作れるとき
      int j=0;
      while(i+1+j < h && mp[i+1+j][0] && mp[i+1+j][1] && mp[i+1+j][2] && mp[i+1+j][3]) j++;
      if(j == 0 || j%2 == 1){
	mp[i][1] = mp[i][2] = mp[i+1][1] = mp[i+1][2] = false;
	ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

C++: #include<iostream>
using namespace std;

int bo[50000][4]={{}};
int cou=0;

void ch(int a,int b){
    if(bo[a+1][b]==0 && bo[a][b+1]==0 && bo[a+1][b+1]==0){
        bo[a][b]=1;
        bo[a+1][b]=1;
        bo[a][b+1]=1;
        bo[a+1][b+1]=1;
        //cout << a << " " << b << endl;
        cou++;
    }
}

int main(){
    int h,n;
    cin >> h >> n;
    for(int i=0;i<n;i++){
        int x,y;
        cin >> x >> y;
        bo[y][x]=0;
    }

    for(int i=0;i<h-1;i++){
        for(int j=0;j<3;j++){
            if(bo[i][j]==0){
                ch(i,j);
            }
        }
    }

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

C++: #include <iostream>
#include <vector>

using namespace std;

int main(){
	int h, n, x, y;
	cin >> h >> n;
	int array[h][4];

	for(int i = 0; i < h; i++){
		array[i][0] = 0;
		array[i][1] = 0;
		array[i][2] = 0;
		array[i][3] = 0;
	}

	for(int i = 0; i < n; i++){
		cin >> x >> y;
		array[y][x] = -1;
	}

	int count = 1;
	for(int i = 0; i < h-1; i++){
		for(int j = 0; j < 3; j++){
			if(array[i][j] == 0 && array[i+1][j] == 0 && array[i][j+1] == 0 && array[i+1][j+1] == 0){
				array[i][j] = count;
				array[i+1][j] = count;
				array[i][j+1] = count;
				array[i+1][j+1] = count;
				count++;
			}
		}
	}

	cout << count-1 << endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
int main()
{
    int dp[10005][1 << 4];
    int row[10005] = {}; //bit
    int H, N;
    cin >> H >> N;
    for(int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        row[y] |= (1 << x);
    }
    fill_n(*dp, 10005 * 16, -INF);
    dp[0][row[0]] = 0;
    for(int i = 0; i < H - 1; i++) {
        for(int j = 0; j < (1 << 4); j++) {
            if(dp[i][j] == -INF) continue;
            dp[i + 1][row[i + 1]] = max(dp[i + 1][row[i + 1]], dp[i][j]);
            if(j == 0 && row[i + 1] == 0) {
                dp[i + 1][(1 << 4) - 1] = max(dp[i + 1][(1 << 4) - 1], dp[i][j] + 2);
            }
            for(int k = 0; k < 3; k++) {
                int bit = (1 << k) | (1 << (k + 1));
                if((j & bit) == 0 && (row[i + 1] & bit) == 0) {
                    dp[i + 1][row[i + 1] | bit] = max(dp[i + 1][row[i + 1] | bit], dp[i][j] + 1);
                }
            }
        }
    }
    int maxv = 0;
    for(int i = 0; i < (1 << 4); i++) {
        maxv = max(dp[H - 1][i], maxv);
    }
    cout << maxv << endl;
    return (0);
}

C++: #include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;
using ipii = pair<int, PII>;

#define fst first
#define snd second
const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}
int dx[4] = {0, 0, 1, 1};
int dy[4] = {0, 1, 0, 1};

int main(void){
	bool f[4][10010] = {};
	
	int H, N;
	cin >> H >> N;
	REP(i, N){
		int x, y;
		cin >> x >> y;
		f[x][H-y-1] = 1;
	}

	int sp[10010] = {};
	vector<int> con;
	int cn = 0;
	REP(i, H){
		int cnt = 0;
		REP(j, 4){
			if(f[j][i])
				cnt++;
		}
		if(cnt == 0){
			if(con.size() == 0)
				con.push_back(0);
			sp[i]++;
			if(i > 0 && sp[i-1] == 0){
				con.push_back(cn);
				cn = 0;
			}
		}else{
			if(i > 0 && sp[i-1] == 1){
				con.push_back(cn);
				cn = 0;
			}
		}
		cn++;
	}
	con.push_back(cn);
	ll res = 0;
	int sum = 0;
	int in = 0;
	vector<int> ei({0, 2, 1});
	REP(i, H-1){
		while(sum < i+2)
			sum += con[in++];
		if(sp[i] == 0){
			if(sp[i+1] == 1){
				if((sum-i-1)%2){
					for(auto k : ei){
						int cnt = 0;
						REP(t, 4){
							if(f[k+dx[t]][i+dy[t]] == 1)
								cnt++;
						}
						if(cnt == 0){
							REP(t, 4){
								f[k+dx[t]][i+dy[t]] = 1;
							}
							res++;
						}
					}
				}
			}else{
				for(auto k : ei){
					int cnt = 0;
					REP(t, 4){
						if(f[k+dx[t]][i+dy[t]] == 1)
							cnt++;
					}
					if(cnt == 0){
						REP(t, 4){
							f[k+dx[t]][i+dy[t]] = 1;
						}
						res++;
					}
				}
			}
		}else{
			for(auto k : ei){
				int cnt = 0;
				REP(t, 4){
					if(f[k+dx[t]][i+dy[t]] == 1)
						cnt++;
				}
				if(cnt == 0){
					REP(t, 4){
						f[k+dx[t]][i+dy[t]] = 1;
					}
					res++;
				}
			}
		}
	}
	cout << res << endl;
}