#include <bits/stdc++.h>
using namespace std;
const int max_n = 51, inf = 1000111222;
struct constraint {
  int l, r, h, c;
  void read() {
    scanf("%d%d%d%d", &l, &r, &h, &c);
    --l;
    --r;
  }
  bool operator<(const constraint &c) const { return h < c.h; }
};
int n, mx_h, m, dp[max_n][max_n][max_n];
constraint a[max_n];
int to;
int main() {
  scanf("%d%d%d", &n, &mx_h, &m);
  for (int i = 0; i < m; ++i) {
    a[i].read();
  }
  sort(a, a + m);
  for (int h = 1; h <= mx_h; ++h) {
    while (to < m && a[to].h < h) {
      ++to;
    }
    for (int len = 1; len <= n; ++len) {
      for (int l = 0; l + len <= n; ++l) {
        int r = l + len - 1;
        dp[h][l][r] = dp[h - 1][l][r];
        for (int pos = l; pos <= r; ++pos) {
          int res = h * h;
          for (int i = 0; i < to; ++i) {
            if (l <= a[i].l && a[i].r <= r && a[i].l <= pos && pos <= a[i].r) {
              res -= a[i].c;
            }
          }
          if (l < pos) {
            res += dp[h][l][pos - 1];
          }
          if (pos < r) {
            res += dp[h][pos + 1][r];
          }
          dp[h][l][r] = max(dp[h][l][r], res);
        }
      }
    }
  }
  printf("%d\n", dp[mx_h][0][n - 1]);
  return 0;
}
