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

Python: h, n = map(int, input().split())
c = {i:set() for i in range(h)}
for i in range(n):
    a, b = map(int, input().split())
    c[b].add(a)
count = 0
for i in range(h - 1):
    l = c[i] | c[i + 1]
    p = None
    if l == set():
        count += 2
        c[i + 1].add(1)
        c[i + 1].add(2)
    elif 0 not in l and 1 not in l:
        p = 1
    elif 2 not in l and 3 not in l:
        p = 3
    elif 1 not in l and 2 not in l:
        p = 2
    if p:
        j = 1
        while i + j < h:
            if c[i + j] == set():
                j += 1
            else:
                break
        if (j - 1) % 2:
            count += 1
            c[i + 1].add(p - 1)
            c[i + 1].add(p)
print(count)

C++: #include <cstdio>
#include <cstring>
#include <algorithm>

const int MAX_RC = 30000;
int R, N;
const int K = 4;
bool grid[MAX_RC][K];
int cache[MAX_RC][1 << K];

int genbits(int r) {
  int a = grid[r][0] ? 1 : 0;
  int b = grid[r][1] ? 2 : 0;
  int c = grid[r][2] ? 4 : 0;
  int d = grid[r][3] ? 8 : 0;
  return a | b | c | d;
}


int dp(int r, int bits) {
  if (r == R - 1) return 0;
  if (cache[r][bits] != -1) return cache[r][bits];
  int max = 0;
  for (int i = 0; i < K - 1; ++i) {
    if (!(bits & (1 << i)) && !(bits & (1 << (i + 1))) && !grid[r][i] && !grid[r][i + 1] && !grid[r + 1][i] && !grid[r + 1][i + 1]) {
      max = std::max(max, dp(r + 1, (1 << i) | (1 << (i + 1))) + 1);
    }
  }
  if (genbits(r) == 0 && genbits(r + 1) == 0 && bits == 0) {
    max = std::max(max, dp(r + 2, 0) + 2);
  }
  max = std::max(max, dp(r + 1, 0));
  cache[r][bits] = max;
  return max;
}

int main() {
  memset(cache, -1, sizeof(cache));
  scanf("%d %d", &R, &N);
  for (int i = 0; i < N; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    grid[y][x] = 1;
  }
  printf("%d\n", dp(0, 0));
}

C++: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

bool ng[10000][4];
int dp[10000][1 << 4];

bool check(int y, int bit) {
    FOR(x, 0, 4)if (ng[y][x] && !(bit & (1 << x))) {
        return false;
    }
    return true;
}

int main() {
    init();

    int h, n;
    cin >> h >> n;
    int x, y;
    FOR(i, 0, n) {
        cin >> x >> y;
        ng[y][x] = true;
    }

    FOR(i, 0, h - 1)FOR(u, 0, 1 << 4)if (check(i, u)) {
        FOR(d, 0, 1 << 4)if (check(i + 1, d)) {
            FOR(x, 0, 3) {
                if (u & (1 << x)) continue;
                if (u & (1 << (x + 1))) continue;
                if (d & (1 << x)) continue;
                if (d & (1 << (x + 1))) continue;
                chmax(dp[i + 1][d + (1 << x) + (1 << (x + 1))], dp[i][u] + 1);
            }

            if (!(u || d))chmax(dp[i + 1][(1 << 4) - 1], dp[i][0] + 2);
            chmax(dp[i + 1][d], dp[i][u]);
        }
    }

    int ans = 0;
    FOR(d, 0, 1 << 4)if (check(h - 1, d))chmax(ans, dp[h - 1][d]);
    cout << ans << "\n";
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <list>
#include <string.h>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cstdio>
#define rep(i, n) for(int i = 0; i < n; i++)
#define fi first
#define se second
//#include <Windows.h>
//#include "Library.h"
//#include "Math.h"
//#include "Othello.h"
using namespace std;
typedef long long int ll; typedef pair <ll, ll> P; typedef vector <int> vecint; typedef pair<int,  P> P1; typedef pair<int, P1> P2;
const int inf = 2000000000;
const ll INF = 9000000000000000000;
const double EPS = 10e-9;
int grid[10000][4];
int main() {
int h, n; cin >> h >> n;
rep(i, n)
{
int a, b; cin >> a >> b; grid[h - b - 1][a] = 1;
}
int res = 0;
rep(i, h - 1)rep(j, 3)
{
if(!grid[i][j] && !grid[i + 1][j] && !grid[i][j + 1] && !grid[i + 1][j + 1])
res++;
}
cout << res << endl;
return 0;
}

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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

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

int H, N;
vi fie;
vvi dp;

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

  int ans = dfs(h + 1, fie[h]);

  rep(i, 0, 3) {
    if((state >> i) & 3) continue;
    if((fie[h] >> i) & 3) continue;
    ans = max(ans, dfs(h + 1, fie[h] | (3 << i)) + 1);
  }

  if(state == 0 && fie[h] == 0) {
    ans = max(ans, dfs(h + 1, (1 << 4) - 1) + 2);
  }

  return dp[h][state] = ans;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> H >> N;
  fie.resize(H);
  dp.resize(H, vi((1 << 4), -1));
  rep(i, 0, N) {
    int x, y;
    cin >> x >> y;
    fie[y] |= (1 << x);
  }

  cout << dfs(1, fie[0]) << endl;
}

C++: #include <bits/stdc++.h>
#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()
using namespace std;

int main(){
    int H,N,F[10100];
    cin>>H>>N;
    long long dp[10100][1<<4],ans;

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

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