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 <stdio.h>

int max(int a, int b) {
  return a > b ? a : b;
}

int main(void) {
  int n, i, j, h;
  scanf("%d%d", &h, &n);
  int a[4][h], dp[5][h];
  for(j = 0; j < h; ++j) {
    for(i = 0; i < 4; ++i) a[i][j] = 1;
    for(i = 0; i < 5; ++i) dp[i][j] = 0;
  }
  for(i = 0; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    a[x][y] = 0;
  }
  if(a[0][0] && a[0][1] && a[1][0] && a[1][1]) dp[1][1] = 1;
  if(a[2][0] && a[2][1] && a[1][0] && a[1][1]) dp[2][1] = 1;
  if(a[3][0] && a[3][1] && a[2][0] && a[2][1]) dp[3][1] = 1;
  if(dp[1][1] && dp[3][1]) dp[4][1] = 2;
  else dp[4][1] = max(dp[1][1], max(dp[2][1], dp[3][1]));
  for(i = 2; i < h; ++i) {
    int s = 1;
    dp[0][i] = dp[4][i - 2];
    if(a[0][i - 1] && a[0][i] && a[1][i - 1] && a[1][i]) dp[1][i] = max(dp[3][i - 1] + 1, dp[4][i - 2] + 1);
    else s = 0;
    if(a[2][i - 1] && a[2][i] && a[1][i - 1] && a[1][i]) dp[2][i] = dp[4][i - 2] + 1;
    if(a[3][i - 1] && a[3][i] && a[2][i - 1] && a[2][i]) dp[3][i] = max(dp[1][i - 1] + 1, dp[4][i - 2] + 1);
    else s = 0;
    for(j = 1; j < 4; ++j) if(!dp[j][i]) dp[j][i] = dp[0][i];
    if(s) dp[4][1] = dp[4][i - 2] + 2;
    else dp[4][i] = max(dp[1][i], max(dp[2][i], dp[3][i]));
  }
  /*for(i = 0; i < h; ++i) {
    for(j = 0; j < 5; ++j) printf("%d ", dp[j][i]);
    printf("\n");
  }*/
  printf("%d\n", dp[4][h - 1]);
  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;
	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;
	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[10101];
long long dp[10101][1<<4];

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

    FOR(i,0,N){
        int x,y; 
        cin>>x>>y;
        F[y] |= (1<<x);
    }

    FOR(i,0,10101){
        FOR(j,0,(1<<4)){
            dp[i][j] = -1e9;
        }
    }

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

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

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