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] {
				//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 <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
//
struct poi{
  int X;int Y;int Z;
  bool operator<(const poi&R)const{
    return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
  }
};
//
//
int H,N;
bool M[40000][4];
int count(){
	bool m[40000][4];
	FOR(i,0,H){
		FOR(j,0,4){
			m[i][j]=M[i][j];
		}
	}
	int cnt=0;
	FOR(i,0,H-1){
		if(!m[i][0]&&!m[i][1]&&!m[i][2]&&!m[i][3]){
			if(!m[i+1][0]&&!m[i+1][1]&&!m[i+1][2]&&!m[i+1][3]){
				FOR(j,0,2){
					FOR(k,0,4){
						m[i+j][k]=true;
					}
				}
				cnt+=2;
			}
		}else if(!m[i][0]&&!m[i][1]&&!m[i+1][0]&&!m[i+1][1]){
			FOR(j,0,2){
				FOR(k,0,2){
					m[i+j][k]=true;
				}
			}
			cnt++;
		}else if(!m[i][1]&&!m[i][2]&&!m[i+1][1]&&!m[i+1][2]){
			FOR(j,0,2){
				FOR(k,1,3){
					m[i+j][k]=true;
				}
			}
			cnt++;
		}else if(!m[i][2]&&!m[i][3]&&!m[i+1][2]&&!m[i+1][3]){
			FOR(j,0,2){
				FOR(k,2,4){
					m[i+j][k]=true;
				}
			}
			cnt++;
		}
	}
	return cnt;
}
int main(){
	cin>>H>>N;
	FOR(i,0,N){
		int X,Y;
		cin>>X>>Y;
		M[Y][X]=true;
	}
	int ans=0;
	if(!M[0][0]&&!M[0][1]&&!M[0][2]&&!M[0][3]){
		if(!M[1][0]&&!M[1][1]&&!M[1][2]&&!M[1][3]){
			FOR(i,0,2){
				FOR(j,0,4){
					M[i][j]=true;
				}
			}
			ans=max(ans,count()+2);
			FOR(i,0,2){
				FOR(j,0,4){
					M[i][j]=false;
				}
			}
		}
	}
	if(!M[0][0]&&!M[0][1]&&!M[1][0]&&!M[1][1]){
		FOR(i,0,2){
			FOR(j,0,2){
				M[i][j]=true;
			}
		}
		ans=max(ans,count()+1);
		FOR(i,0,2){
			FOR(j,0,2){
				M[i][j]=false;
			}
		}
	}
	if(!M[0][1]&&!M[0][2]&&!M[1][1]&&!M[1][2]){
		FOR(i,0,2){
			FOR(j,1,3){
				M[i][j]=true;
			}
		}
		ans=max(ans,count()+1);
		FOR(i,0,2){
			FOR(j,1,3){
				M[i][j]=false;
			}
		}
	}
	if(!M[0][2]&&!M[0][3]&&!M[1][2]&&!M[1][3]){
		FOR(i,0,2){
			FOR(j,2,4){
				M[i][j]=true;
			}
		}
		ans=max(ans,count()+1);
		FOR(i,0,2){
			FOR(j,2,4){
				M[i][j]=false;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

C++: #include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m;
vvi a;

bool f(int i,int j,int k,int t){
	bool B=1;
	if(k&1<<j||k&1<<(j+1)) B=0;
	if(t&1<<j||t&1<<(j+1)) B=0;
	return B;
}

int main(){
	cin>>n>>m;
	a=vvi(n,vi(4));
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		a[y][x]=1;
	}
	vi dp(1<<4,-inf);
	int t=0;
	for(int i=0;i<4;i++) t+=a[0][i]*(1<<i);
	dp[t]=0;
	for(int i=0;i<n-1;i++){
		vi DP(1<<4,-inf);
		int t=0;
		for(int j=0;j<4;j++) t+=a[i+1][j]*(1<<j);
		for(int j=0;j<1<<4;j++){
			if(f(i,0,j,t)&&f(i,2,j,t)) DP[t|3|12]=max(DP[t|3|12],dp[j]+2);
			if(f(i,0,j,t)) DP[t|3]=max(DP[t|3],dp[j]+1);
			if(f(i,2,j,t)) DP[t|12]=max(DP[t|12],dp[j]+1);
			if(f(i,1,j,t)) DP[t|6]=max(DP[t|6],dp[j]+1);
			DP[t]=max(DP[t],dp[j]);
		}
		dp=DP;
	}
	int res=0;
	for(int i=0;i<1<<4;i++) res=max(res,dp[i]);
	cout<<res<<endl;
}

C++: #include <iostream>
using namespace std;
#include <algorithm>
int main(){
  int H,N;
  cin >> H >> N;
  int hight[10010][3];

  for(int i = 0; i < 10010; i++){
    for(int j = 0; j < 3; j++){
      hight[i][j]=1;

    }
  }
  for(int i = 0; i < 3; i++){
    hight[H][i] = 0;
    hight[0][i] = 0;
  }
  for(int i = 0; i < N; i++){
    int x,y;
    cin >> x >> y;
    if(x == 0){
      for(int k = 0; k < 2; k++) hight[y-k+1][x] = 0;
    }
    if(x == 1){
      for(int j = 0; j < 2; j++)
        for(int k = 0; k < 2; k++){
          hight[y-k+1][x-j] = 0;
        }
    }
    if(x == 2){
      for(int j = 0; j < 2; j++)
        for(int k = 0; k < 2; k++){
          hight[y-k+1][x-j] = 0;
        }
    }
    if(x == 3){
      for(int j = 0; j < 2; j++)hight[y-j+1][x-1] = 0;
    }
  }
  /*
  for(int i = 0; i < H; i++){
    for(int j = 0; j < 3; j++){
      cout << hight[i][j] << " ";
    }
    cout << endl;
  }
  */
  int ans = 0;
  for(int i = 1; i < H;i++){
    if(hight[i][0] == 1){
      ans++;
      hight[i][0] = hight[i][1] = hight[i+1][0] = hight[i+1][1] = 0;
    }
    if(hight[i][2] == 1){
      ans++;
      hight[i][2] = hight[i+1][2] = hight[i][1] = hight[i+1][1]=0;
    }
    if(hight[i][1] == 1){
      int temp = 1;
      while(hight[i+temp][0]&&hight[i+temp][2]&&temp+i < H)temp++;
      if(temp%2 == 1){
	ans++;
	for(int j = 0; j < 2; j++)
      hight[i+j][0]=hight[i+j][1]=hight[i+j][2]=0;
      }
   
    }
  }
  cout << ans   << endl;
}

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

int h, n;
vector<int> b;

int dp[101010][10];

int dfs(int i = 1, int bit = 0) {
  if (i == h) {
    return 0;
  }
  bit |= b[i];

  int &ret = dp[i][bit];
  if (~ret)
    return ret;

  ret = 0;
  if (bit == 0)
    ret = max(ret, dfs(i + 1, 0b111) + 2);
  if ((bit & (0b100)) == 0)
    ret = max(ret, dfs(i + 1, 0b110) + 1);
  if ((bit & (0b010)) == 0)
    ret = max(ret, dfs(i + 1, 0b111) + 1);
  if ((bit & (0b001)) == 0)
    ret = max(ret, dfs(i + 1, 0b011) + 1);
  ret = max(ret, dfs(i + 1, 0));

  return ret;
}

int main() {
  memset(dp, -1, sizeof(dp));
  cin >> h >> n;

  int ei[4] = {0b100, 0b110, 0b011, 0b001};
  b.assign(h + 1, 0);
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    b[y + 1] |= ei[x];
    b[y] |= ei[x];
  }

  cout << dfs() << endl;
}

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

int h, n;
vector<int> b;

int dp[101010][10];

int dfs(int i = 1, int bit = 0) {
  if (i == h) {
    return 0;
  }
  bit |= b[i];

  int &ret = dp[i][bit];
  if (~ret)
    return ret;

  ret = 0;
  if (bit == 0)
    ret = max(ret, dfs(i + 1, 0b111) + 2);
  if ((bit & (0b100)) == 0)
    ret = max(ret, dfs(i + 1, 0b110) + 1);
  if ((bit & (0b010)) == 0)
    ret = max(ret, dfs(i + 1, 0b111) + 1);
  if ((bit & (0b001)) == 0)
    ret = max(ret, dfs(i + 1, 0b011) + 1);
  ret = max(ret, dfs(i + 1, 0));

  return ret;
}

int main() {
  memset(dp, -1, sizeof(dp));
  cin >> h >> n;

  int ei[4] = {0b100, 0b110, 0b011, 0b001};
  b.assign(h + 1, 0);
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    b[y + 1] |= ei[x];
    b[y] |= ei[x];
  }

  cout << dfs() << endl;
}