#include <bits/stdc++.h>
using namespace std;
inline void setmin(int &x, int y) {
  if (y < x) x = y;
}
inline void setmax(int &x, int y) {
  if (y > x) x = y;
}
inline void setmin(long long &x, long long y) {
  if (y < x) x = y;
}
inline void setmax(long long &x, long long y) {
  if (y > x) x = y;
}
const int N = 51;
const int inf = (int)1e9 + 1;
const long long big = (long long)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;
int dp[N][N][N];
int cost[N][N][N][N];
int L[N], R[N], x[N], c[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  cout << fixed;
  int n, H, m;
  cin >> n >> H >> m;
  for (int i = 0; i < m; i++) {
    cin >> L[i] >> R[i] >> x[i] >> c[i];
    L[i]--;
    R[i]--;
  }
  for (int i = 0; i < m; i++) {
    if (x[i] == H) {
      continue;
    }
    for (int l = 0; l < L[i] + 1; l++) {
      for (int r = R[i]; r < n; r++) {
        for (int p = L[i]; p < R[i] + 1; p++) {
          cost[l][r][p][x[i] + 1] -= c[i];
        }
      }
    }
  }
  for (int l = 0; l < n; l++) {
    for (int r = l; r < n; r++) {
      for (int p = l; p < r + 1; p++) {
        for (int h = 1; h < H + 1; h++) {
          cost[l][r][p][h] += cost[l][r][p][h - 1];
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      for (int h = 0; h < H + 1; h++) {
        dp[i][j][h] = -inf;
      }
    }
  }
  for (int l = n - 1; l > -1; l--) {
    for (int r = l; r < n; r++) {
      for (int p = l; p < r + 1; p++) {
        for (int h = 0; h < H + 1; h++) {
          int val = h * h + cost[l][r][p][h];
          if (p > l) {
            val += dp[l][p - 1][h];
          }
          if (p < r) {
            val += dp[p + 1][r][h];
          }
          setmax(dp[l][r][h], val);
        }
      }
      for (int h = 1; h < H + 1; h++) {
        setmax(dp[l][r][h], dp[l][r][h - 1]);
      }
    }
  }
  cout << dp[0][n - 1][H] << "\n";
  return 0;
}
