#include <bits/stdc++.h>
using namespace std;
const int N = 60, inf = 1e9 + 42;
struct Edge {
  int u, v;
  long long cap, flow;
  Edge() {}
  Edge(int u, int v, long long cap) : u(u), v(v), cap(cap), flow(0) {}
};
struct Dinic {
  int N;
  vector<Edge> E;
  vector<vector<int>> g;
  vector<int> d, pt;
  Dinic(int N) : N(N), E(0), g(N), d(N), pt(N) {}
  void AddEdge(int u, int v, long long cap) {
    if (u != v) {
      E.emplace_back(Edge(u, v, cap));
      g[u].emplace_back(E.size() - 1);
      E.emplace_back(Edge(v, u, 0));
      g[v].emplace_back(E.size() - 1);
    }
  }
  bool BFS(int S, int T) {
    queue<int> q({S});
    fill(d.begin(), d.end(), N + 1);
    d[S] = 0;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      if (u == T) break;
      for (int k : g[u]) {
        Edge &e = E[k];
        if (e.flow < e.cap && d[e.v] > d[e.u] + 1) {
          d[e.v] = d[e.u] + 1;
          q.emplace(e.v);
        }
      }
    }
    return d[T] != N + 1;
  }
  long long DFS(int u, int T, long long flow = -1) {
    if (u == T || flow == 0) return flow;
    for (int &i = pt[u]; i < g[u].size(); ++i) {
      Edge &e = E[g[u][i]];
      Edge &oe = E[g[u][i] ^ 1];
      if (d[e.v] == d[e.u] + 1) {
        long long amt = e.cap - e.flow;
        if (flow != -1 && amt > flow) amt = flow;
        if (long long pushed = DFS(e.v, T, amt)) {
          e.flow += pushed;
          oe.flow -= pushed;
          return pushed;
        }
      }
    }
    return 0;
  }
  long long MaxFlow(int S, int T) {
    long long total = 0;
    while (BFS(S, T)) {
      fill(pt.begin(), pt.end(), 0);
      while (long long flow = DFS(S, T)) total += flow;
    }
    return total;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, h, m;
  cin >> n >> h >> m;
  Dinic dinic(n * h + m + 2);
  int source = 0, sink = n * h + m + 1;
  for (int i = 0; i < n; ++i) {
    dinic.AddEdge(source, i * h + 1, h * h);
    for (int j = 1; j < h; ++j) {
      dinic.AddEdge(i * h + j, i * h + j + 1, h * h - j * j);
    }
  }
  for (int k = 1; k <= m; ++k) {
    int l, r, x, c;
    cin >> l >> r >> x >> c;
    --l;
    --r;
    if (x == h) {
      continue;
    }
    for (int i = l; i <= r; ++i) {
      dinic.AddEdge(i * h + x + 1, n * h + k, inf);
    }
    dinic.AddEdge(n * h + k, sink, c);
  }
  cout << n * h * h - dinic.MaxFlow(source, sink) << endl;
}
