Problem: 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 will gain a^2 dollars from it.

The city has m zoning restrictions. The i-th restriction says that the tallest house from spots l_i to r_i (inclusive) must be at most x_i.

You would like to build houses to maximize your profit. Determine the maximum profit possible.

Input

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

Each of the next m lines contains three integers l_i, r_i, and x_i (1 ≤ l_i ≤ r_i ≤ n, 0 ≤ x_i ≤ h) — left and right limits (inclusive) of the i-th restriction and the maximum possible height in that range.

Output

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

Examples

Input


3 3 3
1 1 1
2 2 3
3 3 2


Output


14


Input


4 10 2
2 3 8
3 4 7


Output


262

Note

In the first example, there are 3 houses, the maximum height of a house is 3, and there are 3 restrictions. The first restriction says the tallest house between 1 and 1 must be at most 1. The second restriction says the tallest house between 2 and 2 must be at most 3. The third restriction says the tallest house between 3 and 3 must be at most 2.

In this case, it is optimal to build houses with heights [1, 3, 2]. This fits within all the restrictions. The total profit in this case is 1^2 + 3^2 + 2^2 = 14.

In the second example, there are 4 houses, the maximum height of a house is 10, and there are 2 restrictions. The first restriction says the tallest house from 2 to 3 must be at most 8. The second restriction says the tallest house from 3 to 4 must be at most 7.

In this case, it's optimal to build houses with heights [10, 8, 7, 7]. We get a profit of 10^2+8^2+7^2+7^2 = 262. Note that there are two restrictions on house 3 and both of them must be satisfied. Also, note that even though there isn't any explicit restrictions on house 1, we must still limit its height to be at most 10 (h=10).

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,mmx,avx,tune=native")
using namespace std;
const int MOD = 1000000007;
const int UNDEF = -1;
const int INF = (1 << 30) - 2;
template <typename T>
inline bool chkmax(T& aa, T bb) {
  return aa < bb ? aa = bb, true : false;
}
template <typename T>
inline bool chkmin(T& aa, T bb) {
  return aa > bb ? aa = bb, true : false;
}
int rint();
char rch();
long long rlong();
class Dinic {
 public:
  const int DINF = INF;
  struct edge {
    int a, b;
    int cap, flow;
  };
  int dinic_numnodes, dinic_src, dinic_dest;
  vector<int> d, ptr, q;
  vector<edge> dinic_edge;
  vector<vector<int> > dinic_graph;
  void add_edge(int a, int b, int cap) {
    int c = max(a, b);
    if (c >= (int)dinic_graph.size()) dinic_graph.resize(c + 1);
    edge e1 = {a, b, cap, 0};
    edge e2 = {b, a, 0, 0};
    dinic_graph[a].push_back((int)dinic_edge.size());
    dinic_edge.push_back(e1);
    dinic_graph[b].push_back((int)dinic_edge.size());
    dinic_edge.push_back(e2);
  }
  bool dinic_bfs() {
    int qh = 0, qt = 0;
    q[qt++] = dinic_src;
    fill(d.begin(), d.end(), -1);
    d[dinic_src] = 0;
    while (qh < qt && d[dinic_dest] == -1) {
      int v = q[qh++];
      for (size_t i = 0; i < dinic_graph[v].size(); ++i) {
        int id = dinic_graph[v][i], to = dinic_edge[id].b;
        if (d[to] == -1 && dinic_edge[id].flow < dinic_edge[id].cap) {
          q[qt++] = to;
          d[to] = d[v] + 1;
        }
      }
    }
    return d[dinic_dest] != -1;
  }
  int dinic_dfs(int v, int flow) {
    if (!flow) return 0;
    if (v == dinic_dest) return flow;
    for (; ptr[v] < (int)dinic_graph[v].size(); ++ptr[v]) {
      int id = dinic_graph[v][ptr[v]], to = dinic_edge[id].b;
      if (d[to] != d[v] + 1) continue;
      int pushed =
          dinic_dfs(to, min(flow, dinic_edge[id].cap - dinic_edge[id].flow));
      if (pushed) {
        dinic_edge[id].flow += pushed;
        dinic_edge[id ^ 1].flow -= pushed;
        return pushed;
      }
    }
    return 0;
  }
  int get_flow(int src, int dest, int numnodes = -1) {
    if (src == dest) return DINF;
    if (numnodes == -1)
      numnodes = max(max(src, dest) + 1, (int)dinic_graph.size());
    d.resize(numnodes);
    ptr.resize(numnodes);
    q.resize(numnodes);
    dinic_src = src;
    dinic_dest = dest;
    dinic_numnodes = numnodes;
    int flow = 0;
    for (;;) {
      if (!dinic_bfs()) break;
      fill(ptr.begin(), ptr.end(), 0);
      while (int pushed = dinic_dfs(dinic_src, DINF)) flow += pushed;
    }
    return flow;
  }
  void reset(int numnodes = -1) {
    if (numnodes == -1) numnodes = (int)dinic_graph.size();
    dinic_edge.clear();
    for (int v = 0; v < numnodes; v++) dinic_graph[v].clear();
  }
};
Dinic D;
int n, hlim, m;
int posH(int pos, int h) {
  ;
  return m + (pos - 1) * hlim + (h - 1);
}
int con(int c) { return c; }
void assert_unique(vector<int> v) {
  sort(v.begin(), v.end());
  for (int i = 1; i < v.size(); i++)
    ;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  n = rint(), hlim = rint(), m = rint();
  int src = posH(n, hlim) + 1;
  int dest = src + 1;
  {
    vector<int> tmp;
    for (int pos = 1; pos <= n; pos++)
      for (int h = 1; h <= hlim; h++) tmp.push_back(posH(pos, h));
    for (int c = 0; c < m; c++) tmp.push_back(con(c));
    tmp.push_back(src);
    tmp.push_back(dest);
    assert_unique(tmp);
  }
  for (int pos = 1; pos <= n; pos++) {
    for (int h = hlim; h >= 2; h--)
      D.add_edge(posH(pos, h), posH(pos, h - 1), INF);
    for (int h = hlim; h >= 1; h--) D.add_edge(src, posH(pos, h), 2 * h - 1);
  }
  for (int c = 0; c < m; c++) {
    int l = rint(), r = rint(), x = rint(), cost = rint();
    if (x + 1 > hlim) continue;
    for (int pos = l; pos <= r; pos++) {
      D.add_edge(posH(pos, x + 1), con(c), INF);
    }
    D.add_edge(con(c), dest, cost);
  }
  int f = D.get_flow(src, dest);
  int all = n * (hlim * hlim);
  int ans = all - f;
  printf("%d\n", ans);
}
static char stdinBuffer[1024];
static char* stdinDataEnd = stdinBuffer + sizeof(stdinBuffer);
static const char* stdinPos = stdinDataEnd;
void readAhead(size_t amount) {
  size_t remaining = stdinDataEnd - stdinPos;
  if (remaining < amount) {
    memmove(stdinBuffer, stdinPos, remaining);
    size_t sz = fread(stdinBuffer + remaining, 1,
                      sizeof(stdinBuffer) - remaining, stdin);
    stdinPos = stdinBuffer;
    stdinDataEnd = stdinBuffer + remaining + sz;
    if (stdinDataEnd != stdinBuffer + sizeof(stdinBuffer)) *stdinDataEnd = 0;
  }
}
int rint() {
  readAhead(16);
  int x = 0;
  bool neg = false;
  while (*stdinPos == ' ' || *stdinPos == '\n') ++stdinPos;
  if (*stdinPos == '-') {
    ++stdinPos;
    neg = true;
  }
  while (*stdinPos >= '0' && *stdinPos <= '9') {
    x *= 10;
    x += *stdinPos - '0';
    ++stdinPos;
  }
  return neg ? -x : x;
}
char rch() {
  readAhead(16);
  while (*stdinPos == ' ' || *stdinPos == '\n') ++stdinPos;
  char ans = *stdinPos;
  ++stdinPos;
  return ans;
}
long long rlong() {
  readAhead(32);
  long long x = 0;
  bool neg = false;
  while (*stdinPos == ' ' || *stdinPos == '\n') ++stdinPos;
  if (*stdinPos == '-') {
    ++stdinPos;
    neg = true;
  }
  while (*stdinPos >= '0' && *stdinPos <= '9') {
    x *= 10;
    x += *stdinPos - '0';
    ++stdinPos;
  }
  return neg ? -x : x;
}