Problem:
Loading
Aizu Ocean Transport Company (AOTC) accepted a new shipping order. The pieces of the cargo included in this order all have the same square footprint (2m x 2m). The cargo room has a rectangular storage space of 4m width with various longitudinal extents. Each pieces of cargo must be placed in alignment with partition boundaries which form a 1m x 1m square grid. A straddling arrangement with a neighboring partition (for example, protrusion by 50 cm) is not allowed. Neither an angled layout nor stacked placement are allowed. Note also that there may be some partitions on which any cargo loading is prohibited.
AOTC wishes to use the currently available ship for this consignment and needs to know how many pieces of cargo it can accommodate.
Make a program to report the maximum cargo capacity of the cargo space given the following information: the depth (m) of the cargo space and the loading-inhibited partitions.
Input
The input is given in the following format.
H
N
x_1
y_1
x_2
y_2
:
x_N
y_N
The first line provides the longitudinal depth
H
(2 ≤
H
≤ 10
4
) of the cargo space in meters and the number of load-inhibited partitions
N
(0 ≤
N
≤ 4 × 10
4
). Each of the subsequent
N
lines defines the position of the
i
-th load-inhibited partition
x_i
(0 ≤
x_i
≤ 3) and
y_i
(0 ≤
y_i
≤
H
-1) in integers, where
x
= 0 and
y
= 0 indicate the bottom-left corner partition. A load-inhibited partition appears only once in the list.
Output
Output the maximum number of cargo pieces loaded into the cargo space.
Sample Input 1
5 3
0 1
1 2
3 3
Sample Output 1
2
Input example 1 corresponds to the cargo layout shown in the left-most figure.
Sample Input 2
6 4
0 2
1 3
3 4
0 5
Sample Output 2
4

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i=0;i<(ll)(N);i++)
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int main(){
    ll H,N;cin>>H>>N;
    vector<vector<int>>G(4,vector<int>(H,0));
    rep(i,N){
        int x,y;cin>>x>>y;
        G[x][y]=1;
    }
    vector<int>DP(16,-998244353);
    int vv = 0;
    rep(i,4){
        vv+=G[i][0]*(1<<i);
    }
    DP[vv]=0;
    for(int i = 1;i<H;i++){
        int v =0;
        rep(j,4){
            v+=G[j][i]*(1<<j);
        }
        vector<int>nDP(16,-998244353);
        rep(j,16){
            if(DP[j]<0)continue;
            nDP[v]=max(nDP[v],DP[j]);
            if((j&3)==0&&(v&3)==0){
                nDP[v+3]=max(nDP[v+3],DP[j]+1);
            }
            if((j&12)==0&&(v&12)==0){
                nDP[v+12]=max(nDP[v+12],DP[j]+1);
            }
            if((j&6)==0&&(v&6)==0){
                nDP[v+6]=max(nDP[v+6],DP[j]+1);
            }
            if(j==0&&v==0){
                nDP[15]=max(nDP[15],DP[j]+2);
            }
        }
        DP = nDP;
    }
    int ans = 0;
    rep(i,16)ans = max(ans,DP[i]);
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3580
final_rank: 4

code_snippet: #pragma GCC target ("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<complex>
#include<time.h>
#include<cassert>
#include<functional>
#include<numeric>
#include<tuple>
using namespace std;
using ll = long long;
using ld = long double;
using H = pair<ll, ll>;
using P = pair<ll, H>;
using vi = vector<ll>;
#define all(a) (a).begin(),(a).end()
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rng(i,s,n) for(ll i = (s) ; i < (n) ; i++)
#define rep(i,n) rng(i, 0, (n))
#define mkp make_pair
#define vec vector
#define pb emplace_back
#define siz(a) (int)(a).size()
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define getidx(b,i) (lower_bound(all(b),(i))-(b).begin())
#define ssp(i,n) (i==(ll)(n)-1?"\n":" ")
#define ctoi(c) (int)(c-'0')
#define itoc(c) (char)(c+'0')
#define cyes printf("Yes\n")
#define cno printf("No\n")
#define cdf(n) for(int quetimes_=(n);quetimes_>0;quetimes_--)
#define gcj printf("Case #%lld: ",qq123_+1)
#define readv(a,n) a.resize(n,0);rep(i,(n)) a[i]=read()
#define found(a,x) (a.find(x)!=a.end())
constexpr ll mod = (ll)1e9 + 7;
constexpr ll Mod = 998244353;
constexpr ld EPS = 1e-10;
constexpr ll inf = (ll)3 * 1e18;
constexpr int Inf = (ll)15 * 1e8;
constexpr int dx[] = { -1,1,0,0 }, dy[] = { 0,0,-1,1 };
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
ll read() { ll u, k = scanf("%lld", &u); return u; }
string reads() { string s; cin >> s; return s; }
H readh(short g = 0) { H u; int k = scanf("%lld %lld", &u.fs, &u.sc); if (g == 1) u.fs--, u.sc--; if (g == 2) u.fs--; return u; }
bool ina(H t, int h, int w) { return 0 <= t.fs && t.fs < h && 0 <= t.sc && t.sc < w; }
bool ina(int t, int l, int r) { return l <= t && t < r; }
ll gcd(ll i, ll j) { return j ? gcd(j, i % j) : i; }
ll popcount(ll x) {
    int sum = 0; for (int i = 0; i < 60; i++)if ((1ll << i) & x) sum++;
    return sum;
}
template<typename T>
class csum {
    vec<T> v;
public:
    csum(vec<T>& a) :v(a) { build(); }
    csum() {}
    void init(vec<T>& a) { v = a; build(); }
    void build() {
        for (int i = 1; i < v.size(); i++) v[i] += v[i - 1];
    }
    //[l,r]
    T a(int l, int r) {
        if (r < l) return 0;
        return v[r] - (l == 0 ? 0 : v[l - 1]);
    }
    //[l,r)
    T b(int l, int r) {
        return a(l, r - 1);
    }
    T a(pair<int, int>t) {
        return a(t.first, t.second);
    }
    T b(pair<int, int>t) {
        return b(t.first, t.second);
    }
};
class mint {
public:ll v;
      mint(ll v = 0) { s(v % mod + mod); }
      constexpr static int mod = (ll)1e9 + 7;
      constexpr static int fn_ = (ll)2e6 + 5;
      static mint fact[fn_], comp[fn_];
      mint pow(int x) const {
          mint b(v), c(1);
          while (x) {
              if (x & 1) c *= b;
              b *= b;
              x >>= 1;
          }
          return c;
      }
      inline mint& s(int vv) {
          v = vv < mod ? vv : vv - mod;
          return *this;
      }
      inline mint inv()const { return pow(mod - 2); }
      inline mint operator-()const { return mint() - *this; }
      inline mint& operator+=(const mint b) { return s(v + b.v); }
      inline mint& operator-=(const mint b) { return s(v + mod - b.v); }
      inline mint& operator*=(const mint b) { v = v * b.v % mod; return *this; }
      inline mint& operator/=(const mint b) { v = v * b.inv().v % mod; return *this; }
      inline mint operator+(const mint b) const { return mint(v) += b; }
      inline mint operator-(const mint b) const { return mint(v) -= b; }
      inline mint operator*(const mint b) const { return mint(v) *= b; }
      inline mint operator/(const mint b) const { return mint(v) /= b; }
      friend ostream& operator<<(ostream& os, const mint& m) {
          return os << m.v;
      }
      friend istream& operator>>(istream& is, mint& m) {
          int x; is >> x; m = mint(x);
          return is;
      }
      bool operator<(const mint& r)const { return v < r.v; }
      bool operator>(const mint& r)const { return v > r.v; }
      bool operator<=(const mint& r)const { return v <= r.v; }
      bool operator>=(const mint& r)const { return v >= r.v; }
      bool operator==(const mint& r)const { return v == r.v; }
      bool operator!=(const mint& r)const { return v != r.v; }
      explicit operator bool()const { return v; }
      explicit operator int()const { return v; }
      mint comb(mint k) {
          if (k > * this) return mint();
          if (!fact[0]) combinit();
          if (v >= fn_) {
              if (k > * this - k) k = *this - k;
              mint tmp(1);
              for (int i = v; i >= v - k.v + 1; i--) tmp *= mint(i);
              return tmp * comp[k.v];
          }
          return fact[v] * comp[k.v] * comp[v - k.v];
      }//nCk
      mint perm(mint k) {
          if (k > * this) return mint();
          if (!fact[0]) combinit();
          if (v >= fn_) {
              mint tmp(1);
              for (int i = v; i >= v - k.v + 1; i--) tmp *= mint(i);
              return tmp;
          }
          return fact[v] * comp[v - k.v];
      }//nPk
      static void combinit() {
          fact[0] = 1;
          for (int i = 1; i < fn_; i++) fact[i] = fact[i - 1] * mint(i);
          comp[fn_ - 1] = fact[fn_ - 1].inv();
          for (int i = fn_ - 2; i >= 0; i--) comp[i] = comp[i + 1] * mint(i + 1);
      }
}; mint mint::fact[fn_], mint::comp[fn_];
//--------------------------------------------------------------

//---------------------------------------------------------------------

bool a[20000][4];
int h;
int dp[20000][1 << 4];
signed main() {
    cin >> h;
    cdf(read()) {
        int x, y; cin >> x >> y;
        a[y][x] = 1;
    }
    int mx = 0;
    rep(i, h - 1)rep(j, 1 << 4) {
        chmax(dp[i + 1][0], dp[i][j]);
        if (!(j & 1) && !(j & 2) && !a[i][0] && !a[i][1] && !a[i + 1][0] && !a[i + 1][1]) {
            chmax(dp[i + 1][1 | 2], dp[i][j] + 1);
        }
        if (!(j & 2) && !(j & 4) && !a[i + 1][1] && !a[i + 1][2] && !a[i][1] && !a[i][2]) {
            chmax(dp[i + 1][2 | 4], dp[i][j] + 1);
        }
        if (!(j & 4) && !(j & 8) && !a[i + 1][2] && !a[i + 1][3] && !a[i][2] && !a[i][3]) {
            chmax(dp[i + 1][4 | 8], dp[i][j] + 1);
        }
        if (j == 0 && !a[i + 1][0] && !a[i + 1][1] && !a[i + 1][2] && !a[i + 1][3] && !a[i][0] && !a[i][1] && !a[i][2] && !a[i][3]) {
            chmax(dp[i + 1][1 | 2 | 4 | 8], dp[i][j] + 2);
        }
        rep(j, 1 << 4) chmax(mx, dp[i + 1][j]);
    }
    cout << mx << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 35424
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...)
#endif

constexpr int INF = (1 << 30) - 1;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int H, N;
    cin >> H >> N;
    // S[i][j] := おけない区画か
    vector S(H + 1, vector<int>(4));
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> y >> x;
        S[x][y] = true;
    }
    // 番兵
    for (int j = 0; j < 4; j++) S[H][j] = true;
    debug(S);

    // dp[i][v] := i, i + 1 行目の状況が v であるときの荷物の max
    vector dp(H, vector<int>(1 << 8, -INF));
    // 初期値
    dp[0][0] = 0;
    for (int i = 0; i < H - 1; i++) {
        for (int bit = 0; bit < (1 << 8); bit++) {
            // 置かない場合
            {
                int nbit = 0;
                // bit の 2 行目の状況を nbit の 1 行目にする
                for (int y = 0; y < 4; y++) {
                    if (bit & (1 << (4 + y))) nbit |= (1 << y);
                }
                dp[i + 1][nbit] = max(dp[i + 1][nbit], dp[i][bit]);
            }
            // 1 個置く場合
            for (int j = 0; j < 3; j++) {
                // [i, i + 1] × [j, j + 1] に置けるか
                bool flag = true;
                for (int x = 0; x < 2; x++) {
                    for (int y = j; y < j + 2; y++) {
                        if (S[i + x][y] || (bit & (1 << (x * 4 + y)))) flag = false;
                    }
                }
                if (flag) {
                    int nbit = 0;
                    // bit の 2 行目の状況を nbit の 1 行目にする
                    for (int y = 0; y < 4; y++) {
                        if (bit & (1 << (4 + y))) nbit |= (1 << y);
                    }
                    // 置く
                    for (int y = j; y < j + 2; y++) nbit |= (1 << y);
                    dp[i + 1][nbit] = max(dp[i + 1][nbit], dp[i][bit] + 1);
                }
            }
            // 2 個置く場合
            {
                // [i, i + 1] × [0, 4] に置けるか
                bool flag = true;
                for (int x = 0; x < 2; x++) {
                    for (int y = 0; y < 4; y++) {
                        if (S[i + x][y] || (bit & (1 << (x * 4 + y)))) flag = false;
                    }
                }
                if (flag) {
                    int nbit = 0;
                    // bit の 2 行目の状況を nbit の 1 行目にする
                    for (int y = 0; y < 4; y++) {
                        if (bit & (1 << (4 + y))) nbit |= (1 << y);
                    }
                    // 置く
                    for (int y = 0; y < 4; y++) nbit |= (1 << y);
                    dp[i + 1][nbit] = max(dp[i + 1][nbit], dp[i][bit] + 2);
                }
            }
        }
    }

    int ans = *max_element(dp[H - 1].begin(), dp[H - 1].end());
    cout << ans << '\n';
}
accuracy: 1
time_ms: 50
memory_kb: 14168
final_rank: 20

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

int main()
{
	int h,n,w = 4;
	cin >> h >> n;
	vector<vector<int>> a(h,vector<int>(w,false));
	for(int i = 0;i < n;i++){
		int x,y;
		cin >> x >> y;
		a[y][x] = true;
	}
	vector<vector<int>> dp(h,vector<int>((1 << w),-INT_MAX));
	{
		int it = 0;
		for(int i = 0;i < w;i++){
			if(a[0][i]){
				it |= (1 << i);
			}
		}
		dp[0][it] = 0;
	}
	for(int i = 1;i < h;i++){
		int it = 0;
		for(int j = 0;j < w;j++){
			if(a[i][j]){
				it |= (1 << j);
			}
		}
		for(int j = 0;j < (1 << w);j++){
			if(dp[i - 1][j] == -INT_MAX) continue;
			dp[i][it] = max(dp[i][it],dp[i - 1][j]);
			for(int k = 0;k < w - 1;k++){
				if((j & (1 << k)) == 0 && (j & (1 << (k + 1))) == 0 && !a[i][k] && !a[i][k + 1]){
					long long t = it | (1 << k) | (1 << (k + 1));
					dp[i][t] = max(dp[i][t],dp[i - 1][j] + 1);
				}
			}
			if(j == 0 && it == 0){
				dp[i][(1 << w) - 1] = max(dp[i][(1 << w) - 1],dp[i - 1][0] + 2);
			}
		}
	}
	cout << *max_element(dp[h - 1].begin(),dp[h - 1].end()) << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4668
final_rank: 14

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

int main() {
  int H, N;
  cin >> H >> N;
  vector<int> block(H);
  for(int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    block[y] |= 1<<x;
  }
  vector dp(H, vector<int>(16));
  vector<pair<int, int>> tr = {{15, 2}, {3, 1}, {6, 1}, {12, 1}, {0, 0}};
  for(int i = 0; i < H-1; i++) {
    for(int s = 0; s < 16; s++) {
      for(int t = 0; t < 16; t++) {
        for(auto [m, delta] : tr) {
          if((s&m) != 0 || (t&m) != 0) continue;
          if((block[i]&m) != 0 || (block[i+1]&m) != 0) continue;
          dp[i+1][t|m] = max(dp[i+1][t|m], dp[i][s]+delta);
        }
      }
    }
  }
  cout << *max_element(dp[H-1].begin(), dp[H-1].end()) << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4252
final_rank: 9

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

int main() {
	int H, N;
	cin >> H >> N;
	vector<int> bit(H);
	for (int i = 0; i < N; i++) {
		int x, y;
		cin >> x >> y;
		bit[y] |= 1 << x;
	}
	const int INF = 1012345678;
	vector<int> dp(16, -INF);
	dp[15] = 0;
	const vector<int> z = { 0, 3, 6, 12, 15 };
	for (int i = 0; i < H; i++) {
		vector<int> ndp(16, -INF);
		for (int j = 0; j < 16; j++) {
			if (dp[j] != -INF) {
				int vacant = ~(j | bit[i]) & 15;
				for (int k : z) {
					if ((vacant & k) == k) {
						ndp[bit[i] | k] = max(ndp[bit[i] | k], dp[j] + (k == 0 ? 0 : k == 15 ? 2 : 1));
					}
				}
			}
		}
		dp = ndp;
	}
	cout << *max_element(dp.begin(), dp.end()) << endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3456
final_rank: 1

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

int main() {
	int H, N;
	cin >> H >> N;
	vector<vector<int>> S(H, vector<int>(4));
	for (int i = 0; i < N; i++){
		int x, y;
		cin >> x >> y;
		S[y][x] = 1;
	}
	vector<vector<int>> dp(H, vector<int>(8, -1e9));
	dp[0][0] = 0;
	for (int i = 0; i < H - 1; i++){
		for (int j : {0, 1, 2, 4, 5}){
			for (int k : {0, 1, 2, 4, 5}){
				for (int l = 0; l < 3; l++){
					if ((j >> l) & 1){
						S[i][l]++;
						S[i][l + 1]++;
					}
				}
				bool ok = true;
				for (int l = 0; l < 3; l++){
					if ((k >> l) & 1){
						if (S[i][l] + S[i + 1][l] + S[i][l + 1] + S[i + 1][l + 1] > 0){
							ok = false;
						}
					}
				}
				if (ok){
					dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + __builtin_popcount(k));
				}
				for (int l = 0; l < 3; l++){
					if ((j >> l) & 1){
						S[i][l]--;
						S[i][l + 1]--;
					}
				}
			}
		}
	}
	cout << *max_element(dp[H - 1].begin(), dp[H - 1].end()) << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4452
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ll h, n;
    cin >> h >> n;
    vector f(4, vector<bool>(h));
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        f[x][y] = 1;
    }
    vector dp(h, vector<ll>(16));
    ll cnt = 0;
    for (int i = 1; i < h; i++) {
        ll blo = 0;
        vector<bool> ok(4);
        for (int j = 0; j < 4; j++)
            if (f[j][i])
                blo += (1 << j);
            else
                ok[j] = 1;
        for (int j = 0; j < 16; j++) dp[i][blo] = max(dp[i][blo], dp[i - 1][j]);
        for (int j = 0; j < 3; j++) {
            if (ok[j] && ok[j + 1]) {
                if (!f[j][i - 1] && !f[j + 1][i - 1]) {
                    ll ma = 0;
                    for (int k = 0; k < 16; k++) {
                        if (k & (1 << j)) continue;
                        if (k & (1 << (j + 1))) continue;
                        ma = max(ma, dp[i - 1][k]);
                    }
                    dp[i][blo + (1 << j) + (1 << (j + 1))] = ma + 1;
                }
            }
        }
        if (blo == 0) {
            if (!f[0][i - 1] && !f[1][i - 1] && !f[2][i - 1] && !f[3][i - 1]) {
                dp[i][15] = dp[i - 1][0] + 2;
            }
        }
    }
    // for (int i = 0; i < h; i++) {
    //     for (int j = 0; j < 16; j++) cout << dp[i][j] << " ";
    //     cout << endl;
    // }
    ll res = 0;
    for (int i = 0; i < 16; i++) res = max(res, dp[h - 1][i]);
    cout << res << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4784
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;

#define chmax(a,b) a = max(a,b)
int main(){
    int h,n;
    cin>>h>>n;
    vector<vector<int> >e(h);
    for(int i = 0;i<n;i++){
        int x,y;
        cin>>x>>y;
        e[h-1-y].push_back(x);
    }
    vector<vector<int> >dp(1<<4,vector<int>(h+1,0));
    int now = 0;
    for(int i = 0;i<h;i++){
        //cout<<now<<endl;
        int mask = 0;
        for(auto j:e[i]) mask |= 1 << j;
        //cout<<mask<<endl;
        for(int j = 0;j<1<<4;j++){
            if(mask&j) dp[j][i] = 0;
        }
        for(int j = 0;j<1<<4;j++){
            if(mask&j) continue;
            chmax(dp[j|mask][i],dp[j][i]);
            if(mask!=0) dp[j][i] = 0;
        }
        chmax(dp[mask][i],now);
        //cout<<now<<" "<<i<<" "<<mask<<endl;
        if(i==h-1) break;
        for(int j = 0;j<1<<4;j++){
            chmax(now,dp[j][i]);
            if(~j&mask) continue;
            for(int k = 0;k<3;k++){
                if((~j>>k&1)&&(((~j)>>(k+1))&1)){
                    chmax(dp[(1<<k)|(1<<(k+1))][i+1],dp[j][i]+1);
                }
            }
        }
        if(mask==0) chmax(dp[15][i+1],dp[0][i]+2);
    }
    int ans = 0;
    for(int i = 0;i<1<<4;i++) ans = max(ans,dp[i][h-1]);

    cout<<ans<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4428
final_rank: 12

code_snippet: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <cstdint>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <fstream>
#include <cmath>
#include <limits>
#include <chrono>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;

ll ll_gcd(ll a, ll b) {
	if (a < b) return ll_gcd(b, a);
	ll r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

bool x(vector<ll>& z) {
	ll now = 0;
	for (int i = 0; i < z.size(); i++) {
		if (now < i * 10)return false;
		now = max(now, i * 10 + z[i]);
	}
	return true;
}

int main(){
	ll h, n;
	cin >> n >> h;
	vector<int> z(n);
	for (int i = 0; i < h; i++) {
		int a, b;
		cin >> a >> b;
		z[b] |= (1 << a);
	}
	vector<vector<int>> dp(n, vector<int>(16,-10000000));
	dp[0][z[0]] = 0;
	for (int i = 0; i < n-1; i++) {
		for (int j = 0; j < 16; j++) {
			dp[i + 1][z[i + 1]] = max(dp[i + 1][z[i + 1]], dp[i][j]);
			for (int k = 0; k < 3; k++) {
				if ((!(j & (1 << k))) && (!(j & (1 << (k + 1)))) && (!(z[i + 1] & (1 << k))) && (!(z[i + 1] & (1 << (k + 1)))))dp[i + 1][z[i + 1] + 3 * (1 << k)] = max(dp[i + 1][z[i + 1] + 3 * (1 << k)], dp[i][j] + 1);
				if (j == 0 && z[i + 1] == 0)dp[i + 1][15] = max(dp[i + 1][15], dp[i][j] + 2);
			}
		}
	}
		int ans = 0;
		for (int i = 0; i < 16; i++) {
			ans = max(ans, dp[n - 1][i]);
		}
		cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4244
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
const int INF = 100000;
int main(){
  int H, N;
  cin >> H >> N;
  vector<int> x(N), y(N);
  for (int i = 0; i < N; i++){
    cin >> x[i] >> y[i];
  }
  vector<int> S(H, 0);
  for (int i = 0; i < N; i++){
    S[y[i]] |= 1 << x[i];
  }
  vector<vector<int>> dp(H + 1, vector<int>(16, -INF));
  dp[0][15] = 0;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < 16; j++){
      dp[i + 1][S[i]] = max(dp[i + 1][S[i]], dp[i][j]);
      if ((j & 3) == 0 && (S[i] & 3) == 0){
        int x = S[i] | 3;
        dp[i + 1][x] = max(dp[i + 1][x], dp[i][j] + 1);
      }
      if ((j & 6) == 0 && (S[i] & 6) == 0){
        int x = S[i] | 6;
        dp[i + 1][x] = max(dp[i + 1][x], dp[i][j] + 1);
      }
      if ((j & 12) == 0 && (S[i] & 12) == 0){
        int x = S[i] | 12;
        dp[i + 1][x] = max(dp[i + 1][x], dp[i][j] + 1);
      }
      if ((j & 15) == 0 && (S[i] & 15) == 0){
        int x = S[i] | 15;
        dp[i + 1][x] = max(dp[i + 1][x], dp[i][j] + 2);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < 16; i++){
    ans = max(ans, dp[H][i]);
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4408
final_rank: 11

code_snippet: #ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep2(i,s,n) for (int i = s; i < (int)(n); i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
typedef pair<ll,ll> P;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}

const vector<int> ne={0,3,3<<1,3<<2,15};


int main(){
    int h,n;
    cin >> h >> n;
    vector<int> cant(h);
    rep(i,n){
        int a,b;
        cin >> a >> b;
        cant[b]|=1<<a;
    }
    vector<vector<int>> dp(h,vector<int>(1<<4));

    rep(i,h-1)rep(S,1<<4){
        for(int T:ne){
            if(S&T)continue;
            if(T&cant[i])continue;
            if(T&cant[i+1])continue;
            dp[i+1][T|cant[i+1]]=max(dp[i+1][T|cant[i+1]],dp[i][S]+(T==15 ? 2:(T==0 ? 0:1)));
        }
    }
    int ans=0;
    for(int res:dp.back())ans=max(ans,res);
    cout << ans << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 4424
final_rank: 17

code_snippet: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; }

int main() {
    int h, n; cin >> h >> n;
    int board[10010][4];
    rep(i, h) rep(j, 4) board[i][j] = 0;
    rep(i, n) { 
        int x, y; cin >> x >> y;
        board[y][x] = 1;
    }
    int dp[h-1+10][5];
    rep(i, h-1) rep(j, 5) dp[i][j] = 0;
    int l = board[0][0]+board[0][1]+board[1][0]+board[1][1];
    int c = board[0][1]+board[0][2]+board[1][1]+board[1][2];
    int r = board[0][2]+board[0][3]+board[1][2]+board[1][3];
    if (l == 0) dp[0][0] = 1;
    if (c == 0) dp[0][1] = 1;
    if (r == 0) dp[0][2] = 1;
    if (l+r == 0) dp[0][3] = 2;
    
    rep(i, h-1) {
        int l = board[i+1][0]+board[i+1][1]+board[i+2][0]+board[i+2][1];
        int c = board[i+1][1]+board[i+1][2]+board[i+2][1]+board[i+2][2];
        int r = board[i+1][2]+board[i+1][3]+board[i+2][2]+board[i+2][3];
        if (c == 0) chmax(dp[i+1][1], dp[i][4]+1);
        if (l == 0) {
            chmax(dp[i+1][0], dp[i][4]+1);
            chmax(dp[i+1][0], dp[i][2]+1);
        }
        if (r == 0) {
            chmax(dp[i+1][2], dp[i][4]+1);
            chmax(dp[i+1][2], dp[i][0]+1);
        }
        if (l+r == 0) {
            chmax(dp[i+1][3], dp[i][4]+2);
        }
        chmax(dp[i+1][4], dp[i][0]);
        chmax(dp[i+1][4], dp[i][1]);
        chmax(dp[i+1][4], dp[i][2]);
        chmax(dp[i+1][4], dp[i][3]);
        chmax(dp[i+1][4], dp[i][4]);
    }
    int ans = 0;
    rep(i, 5) chmax(ans, dp[h-2][i]);
    cout << ans << endl;
    /*
    rep(i, h-1) {
        rep(j, 5) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    */
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3484
final_rank: 3

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

int main(){
  int H,N;
  cin >> H >> N;
  long long int INF = 1000000000000000000;
  vector<vector<long long int> > dp(H,vector<long long int>(16,-INF));
  vector<vector<bool> > vec(H,vector<bool>(4,true));
  for(int i=0;i<N;i++){
    int x,y;
    cin >> x >> y;
    vec[y][x] = false;
  }
  int a = 0;
  for(int i=0;i<4;i++) if(!vec[0][i]) a += (1<<i);
  dp[0][a] = 0;
  for(int i=1;i<H;i++){
    int b = 0;
    for(int j=0;j<4;j++) if(!vec[i][j]) b += (1<<j);
    long long int M = 0;
    for(int j=0;j<16;j++) M = max(M,dp[i-1][j]);
    dp[i][b] = M;
    for(int j=0;j<16;j++){
      bool flag = true;
      for(int k=0;k<4;k++) if(!vec[i][k]) if(!(j & (1<<k))) flag = false;
      if(!flag) continue;
      int t = j;
      for(int k=0;k<4;k++) if(!vec[i][k]) t -= (1<<k);
      if(t == 12) for(int k=0;k<16;k++) if((!(k & (1<<3))) && (!(k & (1<<2)))) dp[i][j] = max(dp[i][j],dp[i-1][k]+1);
      if(t == 6) for(int k=0;k<16;k++) if((!(k & (1<<2))) && (!(k & (1<<1)))) dp[i][j] = max(dp[i][j],dp[i-1][k]+1);
      if(t == 3) for(int k=0;k<16;k++) if((!(k & (1<<1))) && (!(k & (1<<0)))) dp[i][j] = max(dp[i][j],dp[i-1][k]+1);
      if(t == 15) dp[i][j] = max(dp[i][j],dp[i-1][0]+2);
    }
  }
  long long int ans = -INF;
  for(int i=0;i<16;i++) ans = max(ans,dp[H-1][i]);
  cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 5268
final_rank: 16

code_snippet: #define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<list>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<climits>
#include<iomanip>
#include<cctype>
#include<sstream>
#include<regex>
#include<bitset>
#include<random>
#include<complex>
using namespace std;
#define int long long
#define uint unsigned long long
const int mod=1e9+7;
const int Mod=998244353;
const int inf=mod*mod;
const double eps=1e-9;
int dp[2][32];
bool mp[4][10000];
signed main(){
	int h,n,x,y;
	cin>>h>>n;
	while(cin>>x>>y)
		mp[x][y]=1;
	int*tmp=dp[0],*nxt=dp[1];
	for(int i=0;i<31;i++)
		tmp[i]=-inf;
	for(int i=0;i<4*h;i++){
		for(int j=0;j<32;j++)
			nxt[j]=-inf;
		for(int j=0;j<32;j++){
			nxt[j<<1&31|mp[i%4][i/4]]=max(nxt[j<<1&31|mp[i%4][i/4]],tmp[j]);
			if(!mp[i%4][i/4]&&i%4!=0&&(j&25)==0)
				nxt[j<<1&31|19]=max(nxt[j<<1&31|19],tmp[j]+1);
		}
		swap(tmp,nxt);
	}
	int ans=0;
	for(int i=0;i<32;i++)
		ans=max(ans,tmp[i]);
	cout<<ans<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3460
final_rank: 2

code_snippet: #include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include<iomanip>
#include<cassert>
#include<bitset>
#include<sstream>
#include <unordered_set>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<string> vstring;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
typedef vector<vbool> vvbool;
typedef vector<vpllint> vvpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define mod llint(1e9+7)
#define mod9 998244353
#define Inf 2147483647
#define llInf 9223372036854775807
#define all(x) x.begin(),x.end()
#define isin(i,n) (0<=i&&i<n)

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//セグ木・0-indexed・非再帰・(大きさ・単位元・関数)で初期化
template<typename T>
struct SegTree {
	//比較関数の型
	using F = function<T(T, T)>;
	//二分木を配列で表したもの
	vector<T>seg;
	//木の半分の大きさ
	int siz;
	//単位元
	const T unit;
	//比較する関数
	const F f;

	//大きさn、unit(単位元)、f(モノイド)でsegtreeを初期化する
	SegTree(int n, const T unit, const F f) : unit(unit), f(f) {
		siz = 1;
		while (siz < n)siz <<= 1;
		seg.assign(siz * 2 - 1, unit);
		siz--;
	}

	//k番目にtを入力
	void set(int k, const T& t) {
		seg[k + siz] = t;
	}

	//fによって木を構築する
	void build() {
		for (int i = siz - 1; 0 <= i; i--) {
			seg[i] = f(seg[i * 2 + 1], seg[i * 2 + 2]);
		}
	}

	T operator[](const int i) {
		return seg[i + siz];
	}

	//k番目をxに更新する
	void update(int k, T x) {
		k += siz;
		seg[k] = x;
		while (0 < k) {
			k = (k - 1) >> 1;
			seg[k] = f(seg[k * 2 + 1], seg[k * 2 + 2]);
		}
	}

	//[a,b)について、fした結果を返す
	//半開区域のためa以上b未満の位置を指す
	T query(int a, int b) {
		T l = unit, r = unit;
		for (a += siz, b += siz; a < b; a >>= 1, b >>= 1) {
			if (!(a & 1))l = f(l, seg[a++]);
			if (!(b & 1))r = f(seg[--b], r);
		}
		return f(l, r);
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//nCrをmで割った余りを求める
llint nCr(llint n, llint r, llint m) {
	llint ans = 1;
	for (llint i = 0; i < r; i++) {
		ans *= n - i;
		ans %= m;
	}
	for (llint i = 1; i <= r; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//aのb乗をmで割った余りを求める
llint power(llint a, llint b, llint m) {
	if (b == 1)return a;
	if (b == 0)return 1;
	llint tmp = power(a, (llint)b / 2, m);
	tmp *= tmp;
	tmp %= m;
	if (b % 2 == 1) {
		tmp *= a;
		tmp %= m;
	}
	return tmp;
}

//bitを表すsub,要素数を表すlength
bool next_combination(llint& sub, int length) {
	llint x = sub & -sub, y = sub + x;
	sub = (((sub & ~y) / x) >> 1) | y;
	return sub < (llint)(1 << (llint)length);
}

void Zalgorithm(string& s, vint& a) {
	a[0] = s.size();
	int i = 1, j = 0;
	while (i < s.size()) {
		while (i + j < s.size() && s[j] == s[i + j])j++;
		a[i] = j;
		if (j == 0) { i++; continue; }
		int k = 1;
		while (i + k < s.size() && a[k] + k < j) {
			a[i + k] += a[k]; k++;
		}
		i += k; j -= k;
	}
	return;
}

int main() {
	int h, n;
	cin >> h >> n;
	vint isOK(h, 15);
	rep(i, n) {
		int x, y;
		cin >> y >> x;
		isOK[x] -= 1 << y;
	}
	vvint dp(h, vint(16, 0));
	rep(i, h) {
		if (i == 0) {
			rep(j, 1 << 4)dp[i][j] = -Inf;
			dp[i][isOK[i]] = 0;
		}
		else {
			rep(j, 1 << 4) {
				bool tmp = false;
				rep(k, 4)if (j & (1 << k) && !(isOK[i] & (1 << k)))tmp = true;
				if (tmp)dp[i][j] = -Inf;
			}
			int tmp = 0;
			rep(j, 1 << 4)tmp = max(tmp, dp[i - 1][j]);
			dp[i][isOK[i]] = tmp;
			if ((isOK[i] & 12) == 12) {
				rep(j, 1 << 4) {
					if ((j & 12) == 12) {
						dp[i][isOK[i] & (15 - 12)] = max(dp[i][isOK[i] & (15 - 12)], dp[i - 1][j] + 1);
					}
				}
			}
			if ((isOK[i] & 6) == 6) {
				rep(j, 1 << 4) {
					if ((j & 6) == 6) {
						dp[i][isOK[i] & (15 - 6)] = max(dp[i][isOK[i] & 15 - 6], dp[i - 1][j] + 1);
					}
				}
			}
			if ((isOK[i] & 3) == 3) {
				rep(j, 1 << 4) {
					if ((j & 3) == 3) {
						dp[i][isOK[i] & (15 - 3)] = max(dp[i][isOK[i] & (15 - 3)], dp[i - 1][j] + 1);
					}
				}
			}
			if ((isOK[i] & 15) == 15) {
				rep(j, 1 << 4) {
					if ((j & 15) == 15) {
						dp[i][0] = max(dp[i][0], dp[i - 1][j] + 2);
					}
				}
			}
		}
	}
	int ans = 0;
	rep(i, 1 << 4)ans = max(ans, dp[h - 1][i]);
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4264
final_rank: 10

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); i++)
#define repp(i,n,m) for (int i = m; i < int(n); i++)
using namespace std;
int main(){
    int h, n; cin >> h >> n;
    vector<vector<int>> ar(h,vector<int>(4,0));
    rep(i,n){
        int x, y; cin >> x >> y;
        ar[y][x] += 2;
    }
    vector<int> dp(h+1,0);
    vector<int> jun = {0,2,1};
    vector<vector<int>> best = ar;
    rep(i,h-1){
        int pl = 0;
        int pr = 0;
        rep(d,3){
            int c = jun[d];
            int cnt = 0;
            rep(y,2) cnt += best[i][c+y];
            rep(y,2) cnt += best[i+1][c+y];
            if (cnt == 0){
                rep(y,2) best[i+1][c+y]++;
                pr++;
            }
        }
        vector<int> vest = ar[i+1];
        rep(d,3){
            int c = jun[d];
            int cnt = 0;
            rep(y,2) cnt += ar[i][c+y];
            rep(y,2) cnt += vest[c+y];
            if (cnt == 0){
                rep(y,2) vest[c+y]++;
                pl++;
            }
        }
        if (dp[i+1] + pr >= dp[i] + pl){
            dp[i+2] = dp[i+1] + pr;
        }
        else {
            dp[i+2] = dp[i] + pl;
            best[i+1] = vest;
        }
    }
    cout << dp[h] << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4172
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;
void chmax(int &a,int b){
  a=max(a,b);
}
int main(){
  int H,N;
  cin>>H>>N;
  vector<array<int,16>>dp(H);
  vector<int>A(H);
  for(int i=0,a,b;i<N;i++){
    cin>>a>>b;
    A[b]|=1<<a;
  }
  if((A[0]&0b0011)==0&&(A[1]&0b0011)==0)dp[1][A[1]|0b0011]=1;
  if((A[0]&0b0110)==0&&(A[1]&0b0110)==0)dp[1][A[1]|0b0110]=1;
  if((A[0]&0b1100)==0&&(A[1]&0b1100)==0)dp[1][A[1]|0b1100]=1;
  if((A[0]&0b1111)==0&&(A[1]&0b1111)==0)dp[1][A[1]|0b1111]=2;
  for(int i=2;i<H;i++){
    int t=0;
    for(int j=0;j<16;j++)t=max(dp[i-1][j],t);
    dp[i][A[i]]=t;
    for(int j=0;j<16;j++){
      if(((j^A[i-1])&A[i-1])!=0)continue;
      if((j&0b0011)==0&&(A[i]&0b0011)==0)chmax(dp[i][A[i]|0b0011],1+dp[i-1][j]);
      if((j&0b0110)==0&&(A[i]&0b0110)==0)chmax(dp[i][A[i]|0b0110],1+dp[i-1][j]);
      if((j&0b1100)==0&&(A[i]&0b1100)==0)chmax(dp[i][A[i]|0b1100],1+dp[i-1][j]);
      if((j&0b1111)==0&&(A[i]&0b1111)==0)chmax(dp[i][A[i]|0b1111],2+dp[i-1][j]);
    }
  }
  int ans=0;
  for(int i=0;i<16;i++)chmax(ans,dp[H-2][i]),chmax(ans,dp[H-1][i]);
  cout<<ans<<'\n';
}
accuracy: 1
time_ms: 10
memory_kb: 3908
final_rank: 6

code_snippet: #include<iostream>
#include<algorithm>
using namespace std;
void chmax(int&a,int b){if(a<b)a=b;}
int H,N;
int B[10101];
int dp[10101][1<<8];
main()
{
	cin>>H>>N;
	for(int i=0;i<H;i++)for(int j=0;j<1<<8;j++)dp[i][j]=-1e9;
	for(int i=0;i<N;i++)
	{
		int x,y;cin>>x>>y;
		B[y]|=1<<x;
	}
	dp[0][B[1]<<4|B[0]]=0;
	for(int i=0;i<H-1;i++)for(int j=0;j<1<<8;j++)if(dp[i][j]>=0)
	{
		chmax(dp[i+1][B[i+2]<<4|j>>4],dp[i][j]);
		if(!j)chmax(dp[i+1][B[i+2]<<4|15],dp[i][j]+2);
		if(!(j&0b110011))chmax(dp[i+1][B[i+2]<<4|j>>4|3],dp[i][j]+1);
		if(!(j&0b1100110))chmax(dp[i+1][B[i+2]<<4|j>>4|6],dp[i][j]+1);
		if(!(j&0b11001100))chmax(dp[i+1][B[i+2]<<4|j>>4|12],dp[i][j]+1);
	}
	int ans=0;
	for(int j=0;j<1<<8;j++)chmax(ans,dp[H-1][j]);
	cout<<ans<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 13152
final_rank: 18

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
	int H, N;
	cin >> H >> N;
	int* map = new int[H];
    for (int i = 0; i < H; i++)
		map[i] = 0;
	for (int i = 0; i < N; i++)
	{
		int x, y;
		cin >> x >> y;
		map[y] += 1 << x;
	}
	int dp[10000][1 << 4];
	for (int i = 0; i < H; i++)
		for (int j = 0; j < 1 << 4; j++)
			dp[i][j] = -1;
	int put[4] = { 3,6,12,15 };
	dp[0][map[0]] = 0;
	for (int i = 1; i < H; i++)
	{
		for (int j = 0; j < 4; j++)
		{
			for (int k = 0; k < 1 << 4; k++)
			{
				if (dp[i - 1][k] < 0) continue;
				if (put[j] & k || put[j] & map[i])
					dp[i][map[i]] = max(dp[i][map[i]], dp[i - 1][k]);
				else
					dp[i][map[i] | put[j]] = 
					max(dp[i][map[i] | put[j]], dp[i - 1][k] + (j == 3 ? 2 : 1));
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < 1 << 4; i++)
		ans = max(ans, dp[H - 1][i]);
	cout << ans << endl;
	//cin >> H;
}
accuracy: 1
time_ms: 10
memory_kb: 3792
final_rank: 5