#include <bits/stdc++.h>
using namespace std;
int inline read() {
  int num = 0, neg = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    num = (num << 3) + (num << 1) + c - '0';
    c = getchar();
  }
  return num * neg;
}
const int maxn = 100010, mod = 998244353;
int n, m, h;
int pos(int x, int y) { return (x - 1) * (h + 1) + y + 1; }
int s, t, tot;
struct Edge {
  int nxt, to, val;
} edge[200010];
int cnt = 1, head[10010], cur[10010];
int dep[10010], inque[10010], maxflow;
void add_edge(int x, int y, int z) {
  edge[++cnt].nxt = head[x];
  edge[cnt].to = y;
  edge[cnt].val = z;
  head[x] = cnt;
  edge[++cnt].nxt = head[y];
  edge[cnt].to = x;
  edge[cnt].val = 0;
  head[y] = cnt;
}
bool bfs() {
  for (int i = 1; i <= tot; i++)
    cur[i] = head[i], dep[i] = 2147483647, inque[i] = 0;
  dep[s] = 0;
  queue<int> que;
  que.push(s);
  inque[s] = 1;
  while (!que.empty()) {
    int u = que.front();
    que.pop();
    inque[u] = 0;
    for (int i = head[u]; i; i = edge[i].nxt) {
      int v = edge[i].to;
      if (dep[v] > dep[u] + 1 && edge[i].val) {
        dep[v] = dep[u] + 1;
        if (!inque[v]) que.push(v), inque[v] = 1;
      }
    }
  }
  return dep[t] != 2147483647;
}
int dfs(int x, int flow) {
  int now = 0;
  if (x == t) {
    maxflow += flow;
    return flow;
  }
  int used = 0;
  for (int i = cur[x]; i; i = edge[i].nxt) {
    int v = edge[i].to;
    cur[x] = i;
    if (edge[i].val && dep[v] == dep[x] + 1) {
      if (now = dfs(v, min(edge[i].val, flow - used))) {
        used += now;
        edge[i].val -= now;
        edge[i ^ 1].val += now;
        if (used == flow) break;
      }
    }
  }
  return used;
}
int Dinic() {
  while (bfs()) dfs(s, 2147483647);
  return maxflow;
}
int main() {
  n = read();
  h = read();
  m = read();
  tot = n * (h + 1);
  s = ++tot;
  t = ++tot;
  for (int i = 1; i <= n; i++) add_edge(s, pos(i, 0), h * h);
  for (int i = 1; i <= n; i++) add_edge(pos(i, h), t, 2147483647);
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < h; j++)
      add_edge(pos(i, j), pos(i, j + 1), h * h - (j + 1) * (j + 1));
  for (int i = 1; i <= m; i++) {
    int l = read(), r = read(), x = read(), w = read();
    ++tot;
    add_edge(tot, t, w);
    for (int j = l; j <= r; j++) add_edge(pos(j, x), tot, 2147483647);
  }
  Dinic();
  printf("%d", n * h * h - maxflow);
  return 0;
}
