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>
using namespace std;
inline int read() {
  int x = 0, c = 1;
  char ch = ' ';
  while ((ch > '9' || ch < '0') && ch != '-') ch = getchar();
  while (ch == '-') c *= -1, ch = getchar();
  while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
  return x * c;
}
template <typename T>
inline void Max(T &a, T &b) {
  if (a < b) a = b;
}
template <typename T>
inline void Min(T &a, T &b) {
  if (a > b) a = b;
}
const double pi = (double)acos(-1.0);
const double eps = (double)1e-8;
const int INF = (int)0x3f3f3f3f;
const int MOD = (int)998244353;
const int MAXN = (int)5e3 + 10;
const int MAXM = (int)2e4 + 10;
struct po {
  int to, next, w;
  long long dis;
};
struct MaxFlow {
  int S, T, num;
  po edge[MAXM << 1];
  int head[MAXN];
  long long maxflow, mincost, dis[MAXN], b[MAXN], xb[MAXN], flow[MAXN];
  void Init(int s, int t) {
    S = s;
    T = t;
    num = -1;
    memset(head, -1, sizeof(head));
  }
  void add_edge(int from, int to, int w, long long dis) {
    edge[++num].next = head[from];
    edge[num].to = to;
    edge[num].w = w;
    edge[num].dis = dis;
    head[from] = num;
  }
  void add(int from, int to, int w, long long dis = 0LL) {
    add_edge(from, to, w, dis);
    add_edge(to, from, 0, -dis);
  }
  bool SPFA() {
    memset(b, 0, sizeof(b));
    for (int i = S; i <= T; i++) dis[i] = INF;
    dis[T] = 0;
    b[T] = 1;
    deque<int> q;
    q.push_back(T);
    while (!q.empty()) {
      int u = q.front();
      b[u] = 0;
      q.pop_front();
      for (int i = head[u]; ~i; i = edge[i].next) {
        int v = edge[i].to;
        if (edge[i ^ 1].w > 0 && dis[v] > dis[u] - edge[i].dis) {
          dis[v] = dis[u] - edge[i].dis;
          if (!b[v]) {
            b[v] = 1;
            if (!q.empty() && dis[v] < dis[q.front()])
              q.push_front(v);
            else
              q.push_back(v);
          }
        }
      }
    }
    return dis[S] < INF;
  }
  long long DFS(int u, int low) {
    b[u] = 1;
    if (u == T) return low;
    long long flow = 0;
    for (int i = head[u]; ~i; i = edge[i].next) {
      int v = edge[i].to;
      if (!b[v] && edge[i].w != 0 && dis[u] - edge[i].dis == dis[v]) {
        int check = DFS(v, min(edge[i].w, low));
        if (check > 0) {
          mincost += check * edge[i].dis;
          edge[i].w -= check;
          edge[i ^ 1].w += check;
          low -= check;
          flow += check;
          if (low == 0) break;
        }
      }
    }
    return flow;
  }
  void max_flow() {
    maxflow = 0LL;
    while (SPFA()) {
      b[T] = 1;
      while (b[T]) {
        memset(b, 0, sizeof(b));
        maxflow += DFS(S, INF);
      }
    }
  }
} MF;
void work() {
  int n = read(), h = read(), m = read();
  int s = 0, t = (h + 1) * n + m + 1;
  MF.Init(s, t);
  for (int i = 1; i <= n; i++) {
    MF.add(s, (i - 1) * (h + 1) + 1, INF);
    for (int j = 0; j <= h - 1; j++) {
      int id = (h + 1) * (i - 1) + j + 1;
      MF.add(id, id + 1, h * h - j * j);
    }
  }
  for (int k = 1; k <= m; k++) {
    int l = read(), r = read(), x = read(), c = read();
    int curid = (h + 1) * n + k;
    if (x >= h) continue;
    MF.add(curid, t, c);
    for (int i = l; i <= r; i++) {
      int id = (h + 1) * (i - 1) + 1 + x + 1;
      MF.add(id, curid, INF);
    }
  }
  MF.max_flow();
  printf("%d\n", n * h * h - MF.maxflow);
}
int main() {
  work();
  return 0;
}