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;
const long long INF = 1e10;
struct flow_edge {
  int u, v;
  long long flow = 0, cap;
  flow_edge(int u, int v, long long cap) : u(u), v(v), cap(cap) {}
};
struct dinic {
  vector<flow_edge> edges;
  vector<vector<int> > g;
  int n, m = 0;
  int second, t;
  vector<int> lvl, ptr;
  queue<int> q;
  dinic(int n, int second, int t) : n(n), second(second), t(t) {
    g.resize(n + 1);
    lvl.resize(n + 1);
    ptr.resize(n + 1);
  }
  void add_edge(int a, int b, long long cap) {
    edges.emplace_back(flow_edge(a, b, cap));
    edges.emplace_back(flow_edge(b, a, 0));
    g[a].push_back(m);
    g[b].push_back(m + 1);
    m += 2;
  }
  bool bfs() {
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int id : g[u]) {
        if (edges[id].cap - edges[id].flow < 1) continue;
        if (lvl[edges[id].v] != -1) continue;
        lvl[edges[id].v] = lvl[u] + 1;
        q.push(edges[id].v);
      }
    }
    return lvl[t] != -1;
  }
  long long dfs(int u, long long pushed) {
    if (pushed == 0) return 0;
    if (u == t) return pushed;
    for (int &cid = ptr[u]; cid < g[u].size(); cid++) {
      int id = g[u][cid];
      int v = edges[id].v;
      if (lvl[v] != lvl[u] + 1 || edges[id].cap - edges[id].flow < 1) continue;
      long long tr = dfs(v, min(pushed, edges[id].cap - edges[id].flow));
      if (tr == 0) continue;
      edges[id].flow += tr;
      edges[id ^ 1].flow -= tr;
      return tr;
    }
    return 0;
  }
  long long flow() {
    long long first = 0;
    while (1) {
      fill(lvl.begin(), lvl.end(), -1);
      lvl[second] = 0;
      q.push(second);
      if (!bfs()) break;
      fill(ptr.begin(), ptr.end(), 0);
      while (long long pushed = dfs(second, INF)) first += pushed;
    }
    return first;
  }
};
int SOURCE;
int SINK;
int n, h, m, nodes;
int p(int i, int j) {
  if (j == 0) return SOURCE;
  if (j >= h + 1) return SINK;
  return j * n + i;
}
int restriction(int x) { return nodes - 3 - x; }
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> h >> m;
  nodes = n * (h + 1) + m + 2;
  SOURCE = nodes - 1;
  SINK = nodes - 2;
  dinic d(nodes, SOURCE, SINK);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= h; j++) {
      int a1 = p(i, j);
      int a2 = p(i, j + 1);
      d.add_edge(a1, a2, h * h - j * j);
      d.add_edge(a2, a1, INF);
    }
  }
  for (int i = 0; i < m; i++) {
    int l, r, x, c;
    cin >> l >> r >> x >> c;
    int restr = restriction(i);
    d.add_edge(restr, SINK, c);
    for (int j = l - 1; j <= r - 1; j++) d.add_edge(p(j, x + 1), restr, INF);
  }
  cout << n * h * h - d.flow();
}
