#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
struct E {
  int to, i;
};
const int N = 3e3, M = 1e4, S = N - 2, T = N - 1, INF = 1e9;
int fl[M], cp[M], d[N], pt[N];
vector<E> g[N];
int z = 0;
bool bfs() {
  memset(d, -1, sizeof(d));
  d[S] = 0;
  queue<int> q;
  q.push(S);
  while (!q.empty()) {
    int node = q.front();
    q.pop();
    for (E e : g[node]) {
      if (d[e.to] == -1 && fl[e.i] < cp[e.i]) {
        d[e.to] = d[node] + 1;
        q.push(e.to);
      }
    }
  }
  return d[T] != -1;
}
void addEdge(int a, int b, int c) {
  cp[z] = c;
  g[a].push_back({b, z++});
  cp[z] = 0;
  g[b].push_back({a, z++});
}
int dfs(int node, int flow) {
  if (node == T || flow == 0) return flow;
  for (int& i = pt[node]; i < g[node].size(); i++) {
    E& e = g[node][i];
    if (d[e.to] == d[node] + 1 && cp[e.i] > fl[e.i]) {
      int ret = dfs(e.to, min(flow, cp[e.i] - fl[e.i]));
      if (ret > 0) {
        fl[e.i] += ret;
        fl[e.i ^ 1] -= ret;
        return ret;
      }
    }
  }
  return 0;
}
int maxFlow() {
  int flow = 0;
  while (bfs()) {
    memset(pt, 0, sizeof(pt));
    int ret;
    while ((ret = dfs(S, INF))) {
      flow += ret;
    }
  }
  return flow;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, h, m;
  cin >> n >> h >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= h; j++) {
      addEdge(i * h + j, i * h + j - 1, h * h - j * j);
    }
    addEdge(i * h, T, h * h);
  }
  for (int i = 0; i < m; i++) {
    int l, r, x, c;
    cin >> l >> r >> x >> c;
    l--, r--;
    if (x < h) {
      addEdge(S, n * h + i, c);
      for (int j = l; j <= r; j++) {
        addEdge(n * h + i, j * h + x, INF);
      }
    }
  }
  cout << n * h * h - maxFlow();
  return 0;
}
