#include <bits/stdc++.h>
using namespace std;
inline int read() {
  register int data = 0, w = 1;
  char ch = 0;
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') w = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    data = (data << 1) + (data << 3) + (ch ^ 48), ch = getchar();
  return data * w;
}
int cnt = 1, h[1000005];
struct node {
  int to, next, v;
} w[1000005];
void add(int x, int y, int v) {
  ++cnt;
  w[cnt].to = y;
  w[cnt].next = h[x];
  w[cnt].v = v;
  h[x] = cnt;
  ++cnt;
  w[cnt].to = x;
  w[cnt].next = h[y];
  w[cnt].v = 0;
  h[y] = cnt;
}
int d[1000005], S, T, gap[1000005];
int dfs(int x, int mf) {
  if (x == T) return mf;
  int ret = 0, dlt;
  for (int i = h[x]; i; i = w[i].next) {
    int y = w[i].to;
    if (d[x] == d[y] + 1 && w[i].v) {
      dlt = dfs(y, min(mf, w[i].v));
      ret += dlt;
      w[i].v -= dlt;
      w[i ^ 1].v += dlt;
      mf -= dlt;
      if (!mf || d[S] == T) return ret;
    }
  }
  if (!(--gap[d[x]])) d[S] = T;
  gap[++d[x]]++;
  return ret;
}
int SAP() {
  int ans = 0;
  gap[0] = T;
  while (d[S] < T) ans += dfs(S, 0x3f3f3f3f);
  return ans;
}
int n, lim, m;
int main() {
  n = read(), lim = read(), m = read();
  for (int i = 1; i <= m; i++) {
    int l = read(), r = read(), x = read(), c = read();
    if (x == lim) continue;
    for (int j = l; j <= r; j++) add(j + x * n, n * lim + i, 0x3f3f3f3f);
    add(n * lim + i, n * lim + m + 2, c);
  }
  S = n * lim + m + 1, T = S + 1;
  int ans = lim * lim * n;
  for (int i = 1; i <= n; i++)
    add(S, i, lim * lim), add(i + (lim - 1) * n, T, 0);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= lim - 1; j++)
      add(i + (j - 1) * n, i + j * n, lim * lim - j * j);
  ans -= SAP();
  cout << ans << '\n';
  return 0;
}
