#include <bits/stdc++.h>
using namespace std;
const int MN = 55;
struct D {
  int l, r, x, c;
} p[MN];
int n, m, h;
int dp[MN][MN][MN], c[MN][MN][MN];
int dfs(int l, int r, int x) {
  if (r < l && !x) return 0;
  if (dp[l][r][x]) return dp[l][r][x];
  for (int i = l; i <= r; ++i) {
    int Max = INT_MIN;
    for (int j = 1; j <= h; ++j) c[l][r][j] = 0;
    for (int k = 1; k <= m; ++k)
      if (p[k].l <= i && i <= p[k].r && l <= p[k].l && p[k].r <= r)
        c[l][r][p[k].x + 1] += p[k].c;
    for (int j = 1; j <= x; ++j) {
      if (j) c[l][r][j] += c[l][r][j - 1];
      dp[l][r][j] =
          max(max(Max, dp[l][r][j]),
              dfs(l, i - 1, j) + dfs(i + 1, r, j) + j * j - c[l][r][j]);
      Max = max(Max, dp[l][r][j]);
    }
  }
  return dp[l][r][x];
}
int main() {
  scanf("%d%d%d", &n, &h, &m);
  for (int i = 1; i <= m; ++i)
    scanf("%d%d%d%d", &p[i].l, &p[i].r, &p[i].x, &p[i].c);
  printf("%d", dfs(1, n, h));
  return 0;
}
