#include <bits/stdc++.h>
using namespace std;
const int MAXN = 50 + 10;
const int MAXH = 50 + 10;
int N, M, hlim;
int l[MAXN], r[MAXN], x[MAXN], c[MAXN];
int f[MAXN][MAXN][MAXH] = {0};
int calc(int pl, int pr, int k, int h) {
  int ret = h * h;
  for (int i = 1; i <= M; i++)
    if (pl <= l[i] && l[i] <= k && k <= r[i] && r[i] <= pr && h > x[i])
      ret -= c[i];
  return ret;
}
int getnum() {
  int num = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) num = (num << 3) + (num << 1) + ch - '0', ch = getchar();
  return num;
}
int main() {
  N = getnum(), hlim = getnum(), M = getnum();
  for (int i = 1; i <= M; i++)
    l[i] = getnum(), r[i] = getnum(), x[i] = getnum(), c[i] = getnum();
  for (int len = 1; len <= N; len++)
    for (int i = 1; i <= N - len + 1; i++) {
      int j = i + len - 1;
      for (int h = 0; h <= hlim; h++) {
        f[i][j][h] = f[i][j][h - 1];
        for (int k = i; k <= j; k++)
          f[i][j][h] = max(f[i][j][h],
                           f[i][k - 1][h] + f[k + 1][j][h] + calc(i, j, k, h));
      }
    }
  printf("%d\n", f[1][N][hlim]);
  return 0;
}
