#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e10;
struct flow_edge {
  int u, v;
  long long flow = 0, cap;
  flow_edge(int u, int v, long long cap) : u(u), v(v), cap(cap) {}
};
struct dinic {
  vector<flow_edge> edges;
  vector<vector<int> > g;
  int n, m = 0;
  int second, t;
  vector<int> lvl, ptr;
  queue<int> q;
  dinic(int n, int second, int t) : n(n), second(second), t(t) {
    g.resize(n + 1);
    lvl.resize(n + 1);
    ptr.resize(n + 1);
  }
  void add_edge(int a, int b, long long cap) {
    edges.emplace_back(flow_edge(a, b, cap));
    edges.emplace_back(flow_edge(b, a, 0));
    g[a].push_back(m);
    g[b].push_back(m + 1);
    m += 2;
  }
  bool bfs() {
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int id : g[u]) {
        if (edges[id].cap - edges[id].flow < 1) continue;
        if (lvl[edges[id].v] != -1) continue;
        lvl[edges[id].v] = lvl[u] + 1;
        q.push(edges[id].v);
      }
    }
    return lvl[t] != -1;
  }
  long long dfs(int u, long long pushed) {
    if (pushed == 0) return 0;
    if (u == t) return pushed;
    for (int &cid = ptr[u]; cid < g[u].size(); cid++) {
      int id = g[u][cid];
      int v = edges[id].v;
      if (lvl[v] != lvl[u] + 1 || edges[id].cap - edges[id].flow < 1) continue;
      long long tr = dfs(v, min(pushed, edges[id].cap - edges[id].flow));
      if (tr == 0) continue;
      edges[id].flow += tr;
      edges[id ^ 1].flow -= tr;
      return tr;
    }
    return 0;
  }
  long long flow() {
    long long first = 0;
    while (1) {
      fill(lvl.begin(), lvl.end(), -1);
      lvl[second] = 0;
      q.push(second);
      if (!bfs()) break;
      fill(ptr.begin(), ptr.end(), 0);
      while (long long pushed = dfs(second, INF)) first += pushed;
    }
    return first;
  }
};
int SOURCE;
int SINK;
int n, h, m, nodes;
int p(int i, int j) {
  if (j == 0) return SOURCE;
  if (j >= h + 1) return SINK;
  return j * n + i;
}
int restriction(int x) { return nodes - 3 - x; }
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> h >> m;
  nodes = n * (h + 1) + m + 2;
  SOURCE = nodes - 1;
  SINK = nodes - 2;
  dinic d(nodes, SOURCE, SINK);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= h; j++) {
      int a1 = p(i, j);
      int a2 = p(i, j + 1);
      d.add_edge(a1, a2, h * h - j * j);
      d.add_edge(a2, a1, INF);
    }
  }
  for (int i = 0; i < m; i++) {
    int l, r, x, c;
    cin >> l >> r >> x >> c;
    int restr = restriction(i);
    d.add_edge(restr, SINK, c);
    for (int j = l - 1; j <= r - 1; j++) d.add_edge(p(j, x + 1), restr, INF);
  }
  cout << n * h * h - d.flow();
}
