#include <bits/stdc++.h>
using namespace std;
int cost[55][55];
int dp[55][55][55];
int main() {
  int n, h, m;
  scanf("%d%d%d", &n, &h, &m);
  struct Zone {
    int l, r, x, c;
  };
  vector<Zone> a(m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d%d", &a[i].l, &a[i].r, &a[i].x, &a[i].c);
  }
  for (int len = 1; len <= n; ++len)
    for (int i = 1; i <= n - len + 1; ++i) {
      memset(cost, 0, sizeof(cost));
      int j = i + len - 1;
      for (int v = 0; v < m; ++v)
        if (a[v].l >= i && a[v].r <= j)
          for (int w = a[v].l; w <= a[v].r; ++w) {
            cost[w][a[v].x] += a[v].c;
          }
      for (int maxh = 1; maxh <= h; ++maxh) {
        int val = 0;
        for (int k = i; k <= j; ++k) {
          int tot = 0;
          for (int l = 0; l <= maxh; ++l) {
            val = max(val, l * l + dp[i][k - 1][l] + dp[k + 1][j][l] - tot);
            tot += cost[k][l];
          }
        }
        dp[i][j][maxh] = val;
      }
    }
  printf("%d\n", dp[1][n][h]);
}
