#include <bits/stdc++.h>
using namespace std;
#define int long long
void read (int &x) {
    char ch = getchar(); x = 0; int f = 0;
    while (!isdigit(ch)) { if (ch == '-') f = 1; ch = getchar(); }
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    if (f) x = -x;
}
int n, x, y, f[200], s[200], tp;
int res[200], cnt;
signed main() {
    read (n); f[0] = f[1] = 1;
    for (int i = 2; i <= 87; ++i)
        f[i] = f[i - 1] + f[i - 2];
    int t = n;
    for (int i = 86; i; --i) {
        if (t >= f[i]) {
            ++tp, s[tp] = i, t -= f[i];
        }
    }
    // if (t) puts ("666666");
    // for (int i = 1; i <= tp; ++i) printf ("%lld ", s[i]); puts ("");
    int tag = (s[1] & 1); s[tp + 1] = s[1];
    for (int i = tp; i; --i) s[i] = s[1] - s[i];

    // for (int i = 1; i <= tp; ++i) printf ("%lld ", s[i]); puts ("");
    if (tag) {
        res[++cnt] = 2;
        int now = 1; // 1 x  0 y
        for (int i = 2; i <= tp + 1; ++i) {
            for (int j = s[i - 1] + 1; j <= s[i]; ++j) {
                res[++cnt] = now ? 3 : 4, now ^= 1;
            }
            if (i <= tp) res[++cnt] = now ? 2 : 1;
        }
    } else {
        res[++cnt] = 1;
        int now = 0; // 1 x  0 y
        for (int i = 2; i <= tp + 1; ++i) {
            for (int j = s[i - 1] + 1; j <= s[i]; ++j) {
                res[++cnt] = now ? 3 : 4, now ^= 1;
            }
            if (i <= tp) res[++cnt] = now ? 2 : 1;
        }
    }
    int x = 0, y = 0;
    printf ("%lld\n", cnt);
    for (int i = 1; i <= cnt; ++i) {
        printf ("%lld ", res[i]);
        // if (res[i] == 1) ++x;
        // if (res[i] == 2) ++y;
        // if (res[i] == 3) x = x + y;
        // if (res[i] == 4) y = x + y;
        // printf ("%lld %lld %lld %lld\n", i, res[i], x, y);
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
using pii = pair<int, int>;
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; }

template<typename T>
struct SegmentTree{
  using OP = function<T(T,T)>;

  int n, defn;
  vector<T> node;
  T t;
  OP op;

  SegmentTree(int n_, T t, OP op) : t(t),op(op){
    n = 1;
    defn = n_;
    while(n < n_) n<<=1;
    node.assign(2*n,t);
  }

  void init(int n_){
    n = 1;
    defn = n_;
    while(n < n_) n<<=1;
    node.assign(2*n,t);
  }

  void set(int k,T x){
    node.at(k+n) = x;
  }

  void build(){
    for(int k = n - 1; k > 0; k--){
      node.at(k) = op(node.at(2*k),node.at(2*k+1));
    }
  }

  void change(int k, T x){
    k += n;
    node.at(k) = x;
    while(k >>= 1){
      node.at(k) = op(node.at(2*k),node.at(2*k+1));
    }
  }

  void change(int l, int r, T x){
    for(int k = l; k < r; k++) change(k,x);
  }

  template<typename C>
  void update(int k, C c){
    T x = node.at(k+n);
    T x2 = c(x);
    change(k, x2);
  }

  template<typename C>
  void update(int l, int r, C c){
    for(int k = l; k < r; k++) update(k,c);
  }

  T at(int k){
    return node.at(k+n);
  }

  void add(int k, T a){
    T x = at(k)+a;
    change(k,x);
  }

  T query(int a, int b){
    if(a==0 && b==defn) return all_query();
    T L = t, R = t;
    for(a += n, b += n; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = op(L, node.at(a++));
      if(b & 1) R = op(node.at(--b), R);
    }
    return op(L, R);
  }

  T all_query() { return node.at(1); }

  template<typename C>
  int max_right(int l, C &check){
    if(l == defn) return defn;
    l += n;
    T tm = t;
    do{
      while(l%2 == 0) l >>= 1;
      if(!check(op(tm, node.at(l)))){
        while(l < n){
          l *= 2;
          if(check(op(tm, node.at(l)))){
            tm = op(tm, node.at(l));
            l++;
          }
        }
        return l - n;
      }
      tm = op(tm, node.at(l));
      l++;
    }while((l&-l) != l);
    return defn;
  }

  template<typename C>
  int max_left(int r, C &check){
    if(r == 0) return 0;
    r += n;
    T tm = t;
    do{
      r--;
      while(r>1 && (r%2)) r >>= 1;
      if(!check(op(node.at(r), tm))){
        while(r < n){
          r = 2*r + 1;
          if(check(op(node.at(r), tm))){
            tm = op(node.at(r), tm);
            r--;
          }
        }
        return r + 1 - n;
      }
      tm = op(node.at(r), tm);
    }while((r&-r) != r);
    return 0;
  }
};



int main(){
  int H, W, M; cin >> H >> W >> M;
  vector<int> height(W, H), width(H, W);
  vector<vector<int>> ps(H);

  rep(i, M){
    int x, y; cin >> x >> y; x--; y--;
    chmin(height[y], x); chmin(width[x], y);
    ps[x].emplace_back(y);
  }

  ll ans = 0;

  SegmentTree<int> seg(
    W,
    0,
    [](int a, int b) { return a+b; }
  );
  
  rep(i, W){
    if(i < width[0]) ans += height[i];
    else seg.set(i, 1);
  }
  seg.build();

  rep(i, height[0]){
    for(auto&&y : ps[i]){
      seg.change(y, 1);
    }
    ans += seg.query(0, width[i]);
  }

  cout << ans << endl;
}