#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "URDL";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int& x, int y, int mod = 998244353) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et(int x = -1) {
  printf("%d\n", x);
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 998244353) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
int dp[55][55][55];
int h, l[55], r[55], x[55], c[55];
int cal(int L, int R, int H) {
  int& tmp = dp[L][R][H];
  if (tmp != -1) return tmp;
  if (R < L) return 0;
  int y[51][51] = {0};
  for (int(j) = 1; (j) <= (int)(m); (j)++)
    if (L <= l[j] && r[j] <= R) {
      for (int i = l[j]; i <= r[j]; i++) {
        y[i][x[j]] += c[j];
      }
    }
  for (int i = L; i <= R; i++) {
    for (int(j) = 1; (j) <= (int)(50); (j)++) y[i][j] += y[i][j - 1];
  }
  for (int z = 0; z <= H; z++) {
    for (int i = L; i <= R; i++) {
      int ans = cal(L, i - 1, z) + cal(i + 1, R, z) + z * z;
      if (z) ans -= y[i][z - 1];
      maxtt(tmp, ans);
    }
  }
  return tmp;
}
void fmain(int tid) {
  scanf("%d%d%d", &n, &h, &m);
  for (int(i) = 1; (i) <= (int)(m); (i)++)
    scanf("%d%d%d%d", l + i, r + i, x + i, c + i);
  memset(dp, -1, sizeof dp);
  int ans = 0;
  for (int(i) = 0; (i) < (int)(h + 1); (i)++) maxtt(ans, cal(1, n, i));
  printf("%d\n", ans);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
