#include <bits/stdc++.h>
using namespace std;
const int MN = 101, inf = 1000000005, mod = 1000000007;
const long long INF = 1000000000000000005LL;
struct Dinic {
  int n, source, sink;
  vector<int> starte, d;
  vector<vector<long long> > cap;
  vector<vector<int> > nei;
  inline bool bfs() {
    d = vector<int>(n + 1, -1);
    d[source] = 0;
    vector<int> q(1, source);
    for (long long i = (long long)0; i < (long long)q.size(); i++) {
      int v = q[i];
      for (auto w : nei[v])
        if (d[w] == -1 && cap[v][w]) {
          q.push_back(w);
          d[w] = d[v] + 1;
        }
    }
    return d[sink] != -1;
  }
  long long dfs(int v, long long mincap) {
    if (!mincap || v == sink) return mincap;
    long long fp = 0;
    for (long long i = (long long)starte[v]; i < (long long)nei[v].size();
         i++) {
      if (!mincap)
        break;
      else
        starte[v] = i;
      int w = nei[v][i];
      if (d[w] == d[v] + 1) {
        long long f = dfs(w, min(mincap, cap[v][w]));
        mincap -= f;
        fp += f;
        cap[v][w] -= f;
        cap[w][v] += f;
      }
    }
    return fp;
  }
  Dinic(int n, int source, int sink)
      : n(n),
        source(source),
        sink(sink),
        cap(n + 1, vector<long long>(n + 1, 0)),
        nei(n + 1) {}
  long long flow() {
    long long maxflow = 0;
    while (bfs()) {
      starte = vector<int>(n + 1, 0);
      maxflow += dfs(source, INF);
    }
    return maxflow;
  }
  void add_edge(int from, int to, long long capacity, long long cap2 = 0) {
    nei[from].push_back(to);
    nei[to].push_back(from);
    cap[from][to] += capacity;
    cap[to][from] += cap2;
  }
  vector<int> find_source_cc() {
    bfs();
    vector<int> ans;
    for (int i = 0; i <= n; i++)
      if (d[i] != -1) ans.push_back(i);
    return ans;
  }
};
int L[MN], R[MN], X[MN], C[MN];
int kara[MN], plusz[MN];
int main() {
  int n, h, m;
  scanf("%d%d%d", &n, &h, &m);
  int zysk = n * h * h;
  for (int i = 1; i <= h; ++i) plusz[i] = i * i - ((i - 1) * (i - 1));
  for (int i = 1; i <= m; ++i) scanf("%d%d%d%d", &L[i], &R[i], &X[i], &C[i]);
  for (int i = 1; i <= m; ++i) kara[i] = 2 + n + (h + 1) * n + i;
  int N = 5 + m + n + n + n * h;
  Dinic flow(N, 1, 2);
  for (int i = 1; i <= n; ++i) flow.add_edge(1, 2 + i, inf);
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j <= h; ++j) {
      int cur = (h + 1) * (i - 1) + n + 2 + j + 1;
      flow.add_edge(2 + i, cur, plusz[j]);
      if (j > 0) flow.add_edge(cur, cur - 1, inf);
      for (int k = 1; k <= m; ++k)
        if (L[k] <= i && i <= R[k] && j == X[k] + 1)
          flow.add_edge(cur, kara[k], inf);
    }
  for (int i = 1; i <= m; ++i) flow.add_edge(kara[i], 2, C[i]);
  int koszt = flow.flow();
  printf("%d", zysk - koszt);
}
