#include <bits/stdc++.h>
using namespace std;
using LL = long long;
struct Node {
  int l, r, x, c;
};
const int MAXN = 52;
const int MAXM = 52;
const int MAXH = 52;
int n, h, m;
Node x[MAXM];
int f[MAXN][MAXN][MAXH];
bool z[MAXN][MAXN][MAXH];
int DP(int a, int b, int c) {
  if (a > b) return 0;
  if (z[a][b][c]) return f[a][b][c];
  z[a][b][c] = true;
  if (c == 0) return f[a][b][c] = 0;
  for (int mid = a; mid <= b; ++mid) {
    vector<int> g(c + 1);
    for (int i = 0; i < m; ++i) {
      if (x[i].l < a || b < x[i].r) continue;
      if (x[i].l <= mid && mid <= x[i].r && x[i].x <= c) {
        g[x[i].x] += x[i].c;
      }
    }
    int temp = 0;
    for (int i = 0; i <= c; ++i) {
      f[a][b][c] =
          max(f[a][b][c], DP(a, mid - 1, i) + DP(mid + 1, b, i) + i * i - temp);
      temp += g[i];
    }
  }
  return f[a][b][c];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> h >> m;
  for (int i = 0; i < m; ++i) {
    cin >> x[i].l >> x[i].r >> x[i].x >> x[i].c;
    --x[i].l;
    --x[i].r;
  }
  cout << DP(0, n - 1, h) << endl;
  return 0;
}
