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;
vector<int> bfs(const vector<vector<int> >& g, const vector<vector<int> >& cap,
                int src) {
  vector<int> pre(g.size(), -1);
  queue<int> q;
  pre[src] = src;
  for (q.push(src); !q.empty(); q.pop()) {
    int u = q.front();
    for (int e = 0; e < int(g[u].size()); ++e) {
      int v = g[u][e];
      if (cap[u][v] > 0 && pre[v] < 0) {
        pre[v] = u;
        q.push(v);
      }
    }
  }
  return pre;
}
int dinic(const vector<vector<int> >& g, vector<vector<int> > cap, int src,
          int snk) {
  int flow = 0;
  for (; true;) {
    vector<int> pre = bfs(g, cap, src);
    if (pre[snk] < 0) break;
    for (int e = 0; e < int(g[snk].size()); ++e) {
      int v = g[snk][e];
      if (pre[v] >= 0 && cap[v][snk] > 0) {
        int f = cap[v][snk];
        for (int u = v; pre[u] != u; u = pre[u]) {
          f = min(f, cap[pre[u]][u]);
        }
        cap[v][snk] -= f;
        cap[snk][v] += f;
        for (int u = v; pre[u] != u; u = pre[u]) {
          cap[pre[u]][u] -= f;
          cap[u][pre[u]] += f;
        }
        flow += f;
      }
    }
  }
  return flow;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, h, m;
  cin >> n >> h >> m;
  vector<vector<int> > g(n * h + m + 2);
  vector<vector<int> > cap(n * h + m + 2, vector<int>(n * h + m + 2, 0));
  int src = n * h + m;
  int snk = n * h + m + 1;
  for (int i = 0; i < n; ++i) {
    g[src].push_back(i * h);
    g[i * h].push_back(src);
    cap[src][i * h] = h * h;
    for (int j = 1; j < h; ++j) {
      int u = i * h + (j - 1);
      int v = i * h + j;
      g[u].push_back(v);
      g[v].push_back(u);
      cap[u][v] = h * h - j * j;
    }
  }
  for (int i = 0; i < m; ++i) {
    int l, r, x, c;
    cin >> l >> r >> x >> c;
    --l;
    --r;
    if (x >= h) continue;
    int restr = n * h + i;
    for (int j = l; j <= r; ++j) {
      int u = j * h + x;
      g[u].push_back(restr);
      g[restr].push_back(u);
      cap[u][restr] = c;
    }
    g[restr].push_back(snk);
    g[snk].push_back(restr);
    cap[restr][snk] = c;
  }
  int max_flow = dinic(g, cap, src, snk);
  cout << n * h * h - max_flow << endl;
}
