You are planning to build housing on a street. There are n spots available on the street on which you can build a house. The spots are labeled from 1 to n from left to right. In each spot, you can build a house with an integer height between 0 and h.

In each spot, if a house has height a, you can gain a^2 dollars from it.

The city has m zoning restrictions though. The i-th restriction says that if the tallest house from spots l_i to r_i is strictly more than x_i, you must pay a fine of c_i.

You would like to build houses to maximize your profit (sum of dollars gained minus fines). Determine the maximum profit possible.

Input

The first line contains three integers n,h,m (1 ≤ n,h,m ≤ 50) — the number of spots, the maximum height, and the number of restrictions, respectively.

Each of the next m lines contains four integers l_i, r_i, x_i, c_i (1 ≤ l_i ≤ r_i ≤ n, 0 ≤ x_i ≤ h, 1 ≤ c_i ≤ 5 000).

Output

Print a single integer denoting the maximum profit you can make.

Examples

Input


3 3 3
1 1 1 1000
2 2 3 1000
3 3 2 1000


Output


14


Input


4 10 2
2 3 8 76
3 4 7 39


Output


289

Note

In the first example, it's optimal to build houses with heights [1, 3, 2]. We get a gain of 1^2+3^2+2^2 = 14. We don't violate any restrictions, so there are no fees, so the total profit is 14 - 0 = 14.

In the second example, it's optimal to build houses with heights [10, 8, 8, 10]. We get a gain of 10^2+8^2+8^2+10^2 = 328, and we violate the second restriction for a fee of 39, thus the total profit is 328-39 = 289. Note that even though there isn't a restriction on building 1, we must still limit its height to be at most 10.
#include <bits/stdc++.h>
using namespace std;
struct Dinic {
  using F = int;
  const static F INF = 0x3f3f3f3f;
  struct Edge {
    int v, bro;
    F cap;
    Edge() {}
    Edge(int _v, int _bro, F _cap) : v(_v), bro(_bro), cap(_cap) {}
  };
  vector<Edge> e;
  vector<int> pos, cur;
  int n, s, t, m;
  Dinic(int _n, int _s, int _t) : n(_n), s(_s), t(_t), m(0) {
    pos.assign(n, -1);
    cur.resize(n);
    d.resize(n);
    e.reserve(4e5);
  }
  void add(int u, int v, F c = INF) {
    assert(u < n && v < n);
    e.emplace_back(v, pos[u], c);
    pos[u] = m++;
    e.emplace_back(u, pos[v], 0);
    pos[v] = m++;
  }
  vector<int> d;
  bool bfs() {
    fill(d.begin(), d.end(), -1);
    d[s] = 0;
    queue<int> q;
    q.push(s);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int i = cur[u] = pos[u]; i != -1; i = e[i].bro) {
        int v = e[i].v;
        if (d[v] == -1 && e[i].cap != 0) {
          d[v] = d[u] + 1;
          q.push(v);
        }
      }
    }
    return d[t] != -1;
  }
  F dfs(int u, F lim) {
    if (u == t) return lim;
    F tot = 0;
    for (int& i = cur[u]; i != -1; i = e[i].bro) {
      int v = e[i].v;
      if (e[i].cap != 0 && d[v] == d[u] + 1) {
        F flow = dfs(v, min(e[i].cap, lim - tot));
        tot += flow;
        e[i].cap -= flow;
        e[i ^ 1].cap += flow;
        if (tot == lim) return lim;
      }
    }
    return tot;
  }
  F flow() {
    F res = 0;
    while (bfs()) {
      res += dfs(s, INF);
    }
    return res;
  }
};
struct ProjectSelection {
  int n;
  int s, t;
  Dinic mc;
  using F = Dinic::F;
  F positive;
  ProjectSelection(int _n)
      : n(_n), s(n), t(n + 1), mc(n + 2, s, t), positive(0) {}
  void add_proj(int i, F profit) {
    if (profit >= 0) {
      mc.add(s, i, profit);
      positive += profit;
    } else {
      mc.add(i, t, -profit);
    }
  }
  void add_dep(int u, int v) { mc.add(u, v); }
  F profit() { return positive - mc.flow(); }
};
const int N = 55;
int a[N][N];
int v = 0;
void solve() {
  int n, h, m;
  cin >> n >> h >> m;
  ProjectSelection ps(n * h + m);
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= h; j++) {
      a[i][j] = v++;
      ps.add_proj(a[i][j], 2 * j - 1);
      if (j > 1) {
        ps.add_dep(a[i][j], a[i][j - 1]);
      }
    }
  }
  for (int _ = 0; _ < m; _++) {
    int l, r, x, c;
    cin >> l >> r >> x >> c;
    l--;
    x++;
    if (x <= h) {
      ps.add_proj(v, -c);
      for (int i = l; i < r; i++) {
        ps.add_dep(a[i][x], v);
      }
      v++;
    }
  }
  cout << ps.profit();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  cout << endl;
}
