#include <bits/stdc++.h>
using namespace std;
struct op {
  int go, ne;
  int u;
};
const int N = 10000, inf = 2147483647;
int i, j, n, hi, m, l, r, x, c, ans, maxflow, last, s, t, num, so, ac1, ac2,
    ac3, ac4;
int h[N], b[60][60];
int bh[N], gip[N], cur[N];
op lk[N * 100];
int read() {
  int x = 0;
  char s = getchar();
  while ((s < '0') || (s > '9')) s = getchar();
  while ((s >= '0') && (s <= '9')) x = x * 10 + (s - '0'), s = getchar();
  return x;
}
long long min(long long x, long long y) {
  if (x < y) return x;
  return y;
}
int wll(int x, int y) {
  int have = 0, sum = 0, vp = 0, i = cur[x];
  if (x == t) return y;
  while (i) {
    if ((bh[x] == bh[lk[i].go] + 1) && (lk[i].u)) {
      vp = min(y - have, lk[i].u);
      sum = wll(lk[i].go, vp);
      lk[i].u -= sum;
      lk[i ^ 1].u += sum;
      have += sum;
      if (have == y) return y;
    }
    i = lk[i].ne;
  }
  cur[x] = h[x];
  gip[bh[x]]--;
  if (!gip[bh[x]]) bh[s] = num;
  bh[x]++;
  gip[bh[x]]++;
  return have;
}
void ad(int x, int y, int z) {
  so++;
  lk[so].go = y;
  lk[so].ne = h[x];
  h[x] = so;
  lk[so].u = z;
}
void link(int x, int y, int use) {
  ad(x, y, use);
  ad(y, x, 0);
}
int main() {
  n = read();
  hi = read();
  m = read();
  ans = n * hi * hi;
  so = 1;
  s = 1;
  t = 2;
  num = 2;
  for (i = 1; i <= n; i++) {
    last = s;
    for (j = 0; j <= hi - 1; j++)
      num++, link(last, num, hi * hi - j * j), last = num, b[i][j] = num;
  }
  for (i = 1; i <= m; i++) {
    l = read();
    r = read();
    x = read();
    c = read();
    if (!ac1) {
      ac1 = l;
      ac2 = r;
      ac3 = x;
      ac4 = c;
    }
    num++;
    for (j = l; j <= r; j++) link(b[j][x], num, inf);
    link(num, t, c);
  }
  gip[0] = num;
  while (bh[s] < num) {
    maxflow += wll(s, inf);
  }
  ans -= maxflow;
  printf("%d\n", ans);
  fclose(stdin);
  fclose(stdout);
}
