#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int v, c, nxt;
} e[600010];
int tot = 1;
int first[10010];
void build(int u, int v, int c) {
  e[++tot] = (Edge){v, c, first[u]};
  first[u] = tot;
  return;
}
void adde(int u, int v, int c) {
  build(u, v, c);
  build(v, u, 0);
  return;
}
int S, T;
int dep[10010];
bool bfs() {
  queue<int> q;
  for (int i = S; i <= T; i++) dep[i] = 0;
  dep[S] = 1;
  q.push(S);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = first[u]; i; i = e[i].nxt)
      if (!dep[e[i].v] && e[i].c) {
        dep[e[i].v] = dep[u] + 1;
        q.push(e[i].v);
      }
  }
  if (dep[T]) return true;
  return false;
}
int cur[10010];
int dfs(int u, int flow) {
  if (u == T) return flow;
  for (int &i = cur[u]; i; i = e[i].nxt)
    if (e[i].c && dep[e[i].v] == dep[u] + 1) {
      int d = dfs(e[i].v, min(flow, e[i].c));
      if (d) {
        e[i].c -= d;
        e[i ^ 1].c += d;
        return d;
      }
    }
  return 0;
}
int dinic() {
  int ans = 0;
  while (bfs()) {
    for (int i = S; i <= T; i++) cur[i] = first[i];
    int d;
    while (d = dfs(S, 1e9)) ans += d;
  }
  return ans;
}
int main() {
  int n, h, m;
  scanf("%d %d %d", &n, &h, &m);
  int ans = n * h * h;
  S = 0;
  T = n * h + m + 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= h; j++) adde(S, (i - 1) * h + j, j * 2 - 1);
  for (int i = 1; i <= m; i++) {
    int l, r, x, c;
    scanf("%d %d %d %d", &l, &r, &x, &c);
    adde(n * h + i, T, c);
    for (int j = l; j <= r; j++)
      for (int k = x + 1; k <= h; k++) adde((j - 1) * h + k, n * h + i, 1e9);
  }
  ans -= dinic();
  printf("%d\n", ans);
  return 0;
}
