#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int E = 51 * 51 * 4 + 10;
const int V = 50 * 50 + 50 + 10;
int n, h, m, head[V], jmp[E], trace[V], s, t, cntM = 1, mf;
struct Edge {
  int x, y, c, f;
  Edge() {}
  Edge(int x, int y, int c, int f) : x(x), y(y), c(c), f(f) {}
} e[E];
void addEdge(int x, int y, int c) {
  e[++cntM] = Edge(x, y, c, 0);
  jmp[cntM] = head[x];
  head[x] = cntM;
  e[++cntM] = Edge(y, x, 0, 0);
  jmp[cntM] = head[y];
  head[y] = cntM;
}
bool findAugmentedPath() {
  queue<int> q;
  memset(trace, 0, sizeof trace);
  q.push(s);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i; i = jmp[i]) {
      int v = e[i].y;
      if (!trace[v] && e[i].c > e[i].f) {
        trace[v] = i;
        q.push(v);
      }
    }
  }
  return trace[t];
}
void incFlow() {
  int v = t, delta = inf;
  do {
    int i = trace[v];
    delta = min(delta, e[i].c - e[i].f);
    v = e[i].x;
  } while (v != s);
  v = t;
  do {
    int i = trace[v];
    e[i].f += delta;
    e[i ^ 1].f -= delta;
    v = e[i].x;
  } while (v != s);
  mf += delta;
}
int main() {
  scanf("%d %d %d", &n, &h, &m);
  t = n * h + m + 1;
  for (int i = 0; i < n; ++i) {
    addEdge(s, i * h + 1, h * h);
    addEdge(i * h + h, t, 0);
    for (int j = 1; j < h; ++j) {
      addEdge(i * h + j, i * h + j + 1, h * h - j * j);
    }
  }
  for (int i = 1, l, r, x, c; i <= m; ++i) {
    scanf("%d %d %d %d", &l, &r, &x, &c);
    if (x >= h) continue;
    for (int j = l; j <= r; ++j) {
      addEdge((j - 1) * h + x + 1, n * h + i, inf);
    }
    addEdge(n * h + i, t, c);
  }
  while (findAugmentedPath()) incFlow();
  printf("%d\n", n * h * h - mf);
}
