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 <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int inf = 1012345678;
bool judge(int b1, int b2) {
    for(int i = 0; i < 3; ++i) {
        for(int j = 0; j < 3; ++j) {
            if(-1 <= i - j && i - j <= 1 && ((b1 >> i) & 1) && ((b2 >> j) & 1)) {
                return false;
            }
        }
    }
    return true;
}
int main() {
    int H, N;
    cin >> H >> N;
    vector<int> X(N), Y(N);
    vector<int> f(H - 1, 7);
    for(int i = 0; i < N; ++i) {
        cin >> Y[i] >> X[i];
        if(X[i] != H - 1 && Y[i] != 3) f[X[i]] &= ~(1 << Y[i]);
        if(X[i] != H - 1 && Y[i] != 0) f[X[i]] &= ~(1 << (Y[i] - 1));
        if(X[i] != 0 && Y[i] != 3) f[X[i] - 1] &= ~(1 << Y[i]);
        if(X[i] != 0 && Y[i] != 0) f[X[i] - 1] &= ~(1 << (Y[i] - 1));
    }
    vector<int> dp(8, -inf);
    dp[0] = 0;
    for(int i = 0; i < H - 1; ++i) {
        vector<int> s = { 0, 1, 2, 4, 5 };
        vector<int> score = { 0, 1, 1, 1, 2 };
        vector<int> ndp(8, -inf);
        for(int j : s) {
            if((f[i] & j) != j) continue;
            for(int k : s) {
                if(judge(k, j)) {
                    ndp[j] = max(ndp[j], dp[k] + score[j < 4 ? j : j - 1]);
                }
            }
        }
        dp = ndp;
    }
    int ans = *max_element(dp.begin(), dp.end());
    cout << ans << endl;
    return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>
#include<utility>

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define P pair<int, int>
#define PLI pair<ll, int>

using namespace std;

typedef long long ll;


int H, N;
int f[4][10000] = {};
int dp[10000][1<<4];

bool check(int bit, int shift) {
	if (bit >> shift & 1) return false;
	if (bit >> (shift + 1) & 1) return false;
	return true;
}

int dfs(int now, int b) {
	if (now == H - 1) return 0;
	if (dp[now][b] != -1) return dp[now][b];

	int nx = 0;
	rep(i, 4) {
		nx |= f[i][now+1] << i;
	}

	int ret = 0;
	ret = max(ret, dfs(now + 1, nx));

	rep(i, 3) {
		if (check(b, i) && check(nx, i)) {
			int t = nx;
			t |= 1 << i;
			t |= 1 << (i + 1);
			ret = max(ret, dfs(now + 1, t) + 1);
		}
	}

	if (b == 0 && nx == 0) {
		ret = max(ret, dfs(now + 1, 15) + 2);
	}

	return dp[now][b] = ret;
}

int main() {
	cin >> H >> N;
	rep(i, N) {
		int x, y;
		cin >> x >> y;
		f[x][y] = 1;
	}

	rep(i, H) {
		rep(j, 1<<4) {
			dp[i][j] = -1;
		}
	}

	int s = 0;
	rep(i, 4) {
		s |= f[i][0] << i;
	}

	cout << dfs(0, s) << endl;

	return 0;
}

C++: #include <stdio.h>
const int N=1e4+10;
int max(int a,int b){return a>b?a:b;}
int main(){
	int ans=0,h,n,x,y,a[N][4],dp[N][5];
	bool flag;
	scanf("%d%d",&h,&n);
	for(int i=0;i<4;i++)for(int j=1;j<=h;j++)a[j][i]=0;
	for(int i=0;i<5;i++)for(int j=1;j<=h;j++)dp[j][i]=0;
	for(int i=0;i<5;i++)dp[0][i]=0;
	for(int i=1;i<=n;i++){
		scanf("%d%d",&x,&y);
		y++;
		a[y][x]=1;
	}
	//0=xxxx
	//1=ooxx
	//2=xoox
	//3=xxoo
	//4=oooo
	for(int i=2;i<=h;i++){
		for(int j=0;j<5;j++)dp[i][0]=max(dp[i][0],max(dp[i-2][j],dp[i-1][j]));
		flag=true;
		for(int j=0;j<2;j++)if(a[i][j]|a[i-1][j])flag=false;
		if(flag){
			for(int j=0;j<5;j++)dp[i][1]=max(dp[i][1],dp[i-2][j]+1);
			dp[i][1]=max(dp[i][1],dp[i-1][3]+1);
		}
		flag=true;
		for(int j=1;j<3;j++)if(a[i][j]|a[i-1][j])flag=false;
		if(flag)for(int j=0;j<5;j++)dp[i][2]=max(dp[i][2],dp[i-2][j]+1);
		flag=true;
		for(int j=2;j<4;j++)if(a[i][j]|a[i-1][j])flag=false;
		if(flag){
			for(int j=0;j<5;j++)dp[i][3]=max(dp[i][3],dp[i-2][j]+1);
			dp[i][3]=max(dp[i][3],dp[i-1][1]+1);
		}
		flag=true;
		for(int j=0;j<4;j++)if(a[i][j]|a[i-1][j])flag=false;
		if(flag)for(int j=0;j<5;j++)dp[i][4]=max(dp[i][4],dp[i-2][j]+2);
	}
	for(int i=0;i<5;i++)ans=max(ans,dp[h][i]);
	printf("%d\n",ans);
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int H,N,X,Y;
	int i,j,k;
	int wk1,wk2,wk3;
	int mask[4]={3,6,12,15},smask[4]={1,2,4,8};
	int cnt[4]={1,1,1,2};
	int dp[10001][16],syogai[10001];
	cin>>H>>N;
	for(i=0;i<H;i++){
		syogai[i]=0;
	}
	
	for(i=0;i<N;i++){
		cin>>X>>Y;
		syogai[Y]=(syogai[Y]|smask[X]);
	}
//	for(i=0;i<H;i++) cout<<" syogai= "<<syogai[i]<<endl;

	for(i=0;i<H;i++){
		for(j=0;j<16;j++){
			dp[i][j]=0;
		}
	}
	
	for(i=0;i<4;i++){
		wk1=syogai[0]&mask[i];
		wk2=syogai[1]&mask[i];
		if(wk1==0&&wk2==0){
			cout<<" i= "<<i<<endl;
			wk3=syogai[1]|mask[i];
			dp[1][wk3]=cnt[i];
		}
	}
	
	//for(i=0;i<16;i++) cout<<dp[1][i]; cout<<endl;
	
	for(i=1;i<H-1;i++){
		for(j=0;j<16;j++){
			wk3=syogai[i+1];
			dp[i+1][wk3]=max(dp[i+1][wk3],dp[i][j]);
			for(k=0;k<4;k++){
				wk1=(j|syogai[i])&mask[k];
				wk2=syogai[i+1]&mask[k];
				if(wk1==0&&wk2==0){
					wk3=syogai[i+1]|mask[k];
					dp[i+1][wk3]=max(dp[i+1][wk3],dp[i][j]+cnt[k]);
				}
			}
		}
	}
	/*for(i=0;i<16;i++){cout<<i;}
	cout<<endl;
	
	for(i=0;i<H;i++){
		for(j=0;j<16;j++){
			if(j>9){
				cout<<" ";
			}
			cout<<dp[i][j];
		}
		cout<<endl;
		
	}*/
	
	
	int Max=-1;
	for(i=0;i<16;i++){
		Max=max(dp[H-1][i],Max);
	}
	cout<<Max<<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;
}