#include <bits/stdc++.h>
using namespace std;
struct restriction {
  int l, r, x, c;
  bool operator<(restriction o) const { return x < o.x; }
};
int n, h, m;
restriction r[60];
long long memo[60][60][60];
bool check[60][60][60];
long long max_profit(int i, int j, int h) {
  if (i > j) return 0;
  if (check[i][j][h]) return memo[i][j][h];
  long long ret = 0;
  for (int p = i; p <= j; p++) {
    long long sumc = 0;
    for (int k = 0; k < m; k++) {
      if (i <= r[k].l and r[k].r <= j and r[k].l <= p and p <= r[k].r and
          r[k].x < h) {
        int x = r[k].x;
        ret = max(ret, x * x + max_profit(i, p - 1, x) +
                           max_profit(p + 1, j, x) - sumc);
        sumc += r[k].c;
      }
    }
    ret = max(ret,
              h * h + max_profit(i, p - 1, h) + max_profit(p + 1, j, h) - sumc);
  }
  check[i][j][h] = true;
  return memo[i][j][h] = ret;
}
int main() {
  while (scanf("%d%d%d", &n, &h, &m) > 0) {
    for (int i = 0; i < m; i++) {
      scanf("%d%d%d%d", &r[i].l, &r[i].r, &r[i].x, &r[i].c);
    }
    sort(r, r + m);
    memset(check, false, sizeof check);
    printf("%lld\n", max_profit(1, n, h));
  }
}
