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++: // 2017/09/21 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

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

	int R[10000][4];
	for(int y=0; y<H; y++){
		for(int x=0; x<4; x++){
			R[y][x] = 0;
		}
	}

	for(int i=0; i<N; i++){
		int x, y;
		cin >> x >> y;

		R[y][x] = 1;
	}
/*
	for(int y=0; y<H; y++){
		for(int x=0; x<4; x++){
			cout << R[y][x];
		}
		cout << endl;
	}
*/
	int DP[10000][5];
	DP[0][0] = DP[0][1] = DP[0][2] = DP[0][3] = DP[0][4] = 0;

	for(int y=1; y<H; y++){
		DP[y][0] = max(max(max(max(DP[y-1][0], DP[y-1][1]), DP[y-1][2]), DP[y-1][3]), DP[y-1][4]);

		if(R[y][0]+R[y][1]+R[y-1][0]+R[y-1][1]==0){
			DP[y][1] = max(DP[y-1][0]+1, DP[y-1][3]+1);
		}
		else{
			DP[y][1] = -1;
		}

		if(R[y][1]+R[y][2]+R[y-1][1]+R[y-1][2]==0){
			DP[y][2] = DP[y-1][0]+1;
		}
		else{
			DP[y][2] = -1;
		}

		if(R[y][2]+R[y][3]+R[y-1][2]+R[y-1][3]==0){
			DP[y][3] = max(DP[y-1][0]+1, DP[y-1][1]+1);
		}
		else{
			DP[y][3] = -1;
		}

		if(R[y][0]+R[y][1]+R[y][2]+R[y][3]+R[y-1][0]+R[y-1][1]+R[y-1][2]+R[y-1][3]==0){
			DP[y][4] = DP[y-1][0]+2;
		}
		else{
			DP[y][4] = -1;
		}
	}
/*
	for(int y=0; y<H; y++){
		for(int j=0; j<5; j++){
			cout << DP[y][j] << ' ';
		}
		cout << endl;
	}
*/
	cout << max(max(max(max(DP[H-1][0], DP[H-1][1]), DP[H-1][2]), DP[H-1][3]), DP[H-1][4]) << endl;

	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int h, n;
	cin >> h >> n;
	vvi ship(h, vi(4, 1));
	rep(i, 0, n) {
		int x, y;
		cin >> x >> y;
		ship[y][x] = 0;
	}
	
	int ans = 0;
	rep(i, 0, h - 1) {
		rep(j, 0, 3) {
			if (ship[i][j]) {
				if (ship[i + 1][j] && ship[i][j + 1] && ship[i + 1][j + 1]) {
					ans++;
					ship[i][j] = ship[i][j + 1] = 0;
					ship[i + 1][j] = ship[i + 1][j + 1] = 0;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

C++: #include <stdio.h>
#include <algorithm>
#define MAX_H 100000
int blocked[MAX_H];
int dp[2][1<<4];

main() {
 int h, n; scanf("%d %d", &h, &n);
 int x, y;
 for ( int i=0; i<n; ++i ) {
  scanf("%d %d", &x, &y); blocked[y] |= 1<<x;
 }
 int locate[5] = { 0x0, 0x3, 0x6, 0xc, 0xf };//置き方パターン
 int add[5] = { 0, 1, 1, 1, 2 };//各置き方パターンで置ける個数

 int* crt = dp[0];
 int* next = dp[1];

 for ( int obstacle=0; obstacle<1<<4; ++obstacle ) {
if ( obstacle&blocked[0] ) crt[obstacle] = -1;
else crt[obstacle] = 0;
 }

 for ( int i=0; i<h-1; ++i ) {
  std::fill( next, next+(1<<4), -1 );
   for ( int obstacle=0; obstacle<1<<4; ++obstacle ) { //既に有るものパターン(current)
     if ( crt[obstacle] == -1 ) continue;
     for ( int k=0; k<5; ++k ) { //置き方パターン(next)
      int check0 = blocked[i] & locate[k];
      int check1 = blocked[i+1] & locate[k];
     if ( !check0 && !check1 && !(obstacle&locate[k])) {
      int patt = blocked[i+1] | locate[k];
      next[patt] = std::max( crt[obstacle] + add[k], next[patt] );
   }
  }
}
int* tmp = crt;
crt = next;
next = tmp;
 }
 int res = 0;
 for ( int i=0; i<1<<4; ++i ) if ( next[i] > res ) res = next[i];
 printf("%d¥n", res );
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define RREP(i,n) RFOR(i,0,n)

const int _N = 3e5 + 100;
int bitcount[] = {0,1,1,2,1,2,2,3};

int h,n;
bool b[4][10000];
int dp[2][1<<3];

int main(){
	cin >> h >> n;
	REP(i, n){
		int x,y;
		cin >> x >> y;
		b[x][y] = true;
	}
	REP(y, h-1){
		int *prev = dp[0];
		int *now = dp[1];
		REP(i, 1 << 3){
			now[i] = 0;
			REP(j, 1 << 3){
				bool flag = false;

				// check y height block
				REP(x, 3)REP(dx, 2)REP(dy, 2)
					if((i & (1 << x)) && b[x + dx][y + dy])
						flag = true;

				// check (y+1) height block
				if(y>=1)REP(x, 3)REP(dx, 2)REP(dy, 2)
					if((j & (1 << x)) && b[x + dx][y - 1 + dy])
						flag = true;

				// check hit i and j
				REP(x, 2)REP(dxi, 2)REP(dxj, 2)
					if((i & (1 << (x + dxi))) && (j & (1 << (x + dxj))))
						flag = true;

				// check in only i and in only j
				REP(x, 2)if((i & (1 << (x + 1))) && (i & (1 << x)))
					flag = true;
				REP(x, 2)if((j & (1 << x)) && (j & (1 << (x + 1))))
					flag = true;

				if(flag)continue;
				now[i] = max(now[i], prev[j] + bitcount[i]);
			}
		}
		swap(dp[0], dp[1]);
	}
	int ans = 0;
	REP(i, 1<<3)
		ans = max(ans, dp[0][i]);
	cout << ans << endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int h,n;
  cin >> h >> n;
  vector<vector<int>> e(h,vector<int>(4,0));
  rep(i,n){
    int x,y;
    cin >> x >> y;
    e[y][x]=1;
  }
  vector<vector<int>> a(h,vector<int>(5,0));
  for (int i=1;i<h;i++){
    rep(j,5){
      a[i][0]=max(a[i][0],a[i-1][j]);
    }
    bool t=true;
    rep(j,4){
      if (e[i-1][j]==1 || e[i][j]==1) t=false;
    }
    if (t) a[i][1]=a[i-1][0]+2;
    rep(j,3){
      t=true;
      rep(k,2){
        if (e[i-1][j+k]==1 || e[i][j+k]==1) t=false;
      }
      if (t){
        if (j==0){
          a[i][2]=max(a[i-1][0],a[i-1][4])+1;
        }
        if (j==1){
          a[i][3]=a[i-1][0]+1;
        }
        if (j==2){
          a[i][4]=max(a[i-1][0],a[i-1][2])+1;
        }
      }
    }
  }
  int ans=0;
  rep(i,5) ans=max(ans,a[h-1][i]);
  cout << ans << endl;
}

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