#include <bits/stdc++.h>
using namespace std;
bool home = 1;
signed realMain();
mt19937 rng_home(0);
mt19937 rng_oj((long long)(new char));
long long rng() {
  if (home) {
    return rng_home();
  } else {
    return rng_oj();
  }
}
unsigned long long rng_ull() {
  return (unsigned long long)rng() * rng() ^
         ((unsigned long long)rng() * rng());
}
long long rng_range(long long l, long long r) {
  return l + abs(rng()) % (r - l + 1);
}
signed main() {
  home = 0;
  if (home) {
    freopen("input", "r", stdin);
  } else {
    ios::sync_with_stdio(0);
    cin.tie(0);
  }
  realMain();
}
const long long N = 50 + 1;
long long n, lim, m, ff[N], ss[N], over[N], pay[N], jmen[N], dp[N][N][N];
signed realMain() {
  cin >> n >> lim >> m;
  for (long long i = 1; i <= m; i++) {
    cin >> ff[i] >> ss[i] >> over[i] >> pay[i];
  }
  for (long long l = n; l >= 1; l--) {
    for (long long r = l; r <= n; r++) {
      for (long long h = 1; h <= lim; h++) {
        dp[l][r][h] = dp[l][r][h - 1];
        for (long long j = 1; j <= n; j++) {
          jmen[j] = 0;
        }
        for (long long j = 1; j <= m; j++) {
          if (l <= ff[j] && ss[j] <= r && h > over[j]) {
            jmen[ff[j]] += pay[j];
            jmen[ss[j] + 1] -= pay[j];
          }
        }
        for (long long j = 1; j <= n; j++) {
          jmen[j] += jmen[j - 1];
        }
        for (long long p = l; p <= r; p++) {
          dp[l][r][h] = max(
              dp[l][r][h], dp[l][p - 1][h] + dp[p + 1][r][h] + h * h - jmen[p]);
        }
      }
    }
  }
  cout << dp[1][n][lim] << "\n";
  return 0;
}
