#include <atcoder/lazysegtree.hpp>
using namespace atcoder;

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)

#define chmin(x, y) x = min(x, y)
// #include <all.hpp>

// #define int long long

int op(int a, int b) {
  return a + b;
}

int e() {
  return 0;
}

int mapping(int f, int x) {
  if(f < 0) return x;
  return f;
}

int composition(int f, int g) {
  if(f == -1) return g;
  return f;
}

int id() {
  return -1;
}

signed main() {
  int n;
  cin >>n ;
  vector<int> h(n);

  rep(i, n) cin >> h[i];
  auto hh = h;
  sort(hh.begin(), hh.end());
  hh.erase(unique(hh.begin(), hh.end()), hh.end());
  map<int, int> mp;
  rep(i, hh.size()) mp[hh[i]] = i;
  lazy_segtree<int, op, e, int, mapping, composition, id> seg(hh.size()+1);
  rep(i, n) {
    cout << 0 << " " << mp[h[i]] + 1 << " " << 1 - i%2 << endl;
    seg.apply(0, mp[h[i]]+1, 1 - i%2);
  }
  int ans = 0;
  rep(i, hh.size()+1) {
    if(seg.get(i)) {
      ans += hh[i] - (i == 0 ? 0 :hh[i-1]);
    }
  }
  cout << ans << endl;
}