#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "URDL";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int& x, int y, int mod = 998244353) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et(int x = -1) {
  printf("%d\n", x);
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 998244353) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
class MaxFlow {
 public:
  int cap[100000], flow[100000];
  int to[100000], prev[100000], last[10000], used[10000], level[10000];
  int V, E;
  MaxFlow(int n) {
    V = n;
    E = 0;
    for (int(i) = 0; (i) < (int)(V); (i)++) last[i] = -1;
  }
  void init(int n, int es) {
    V = n;
    E = 0;
    for (int(i) = 0; (i) < (int)(V); (i)++) last[i] = -1;
    for (int(i) = 0; (i) < (int)(V); (i)++) {
      used[i] = 0;
      level[i] = 0;
    }
    for (int(i) = 0; (i) < (int)(es); (i)++) {
      cap[i] = flow[i] = to[i] = prev[i] = 0;
    }
  }
  void add_edge(int x, int y, int f) {
    cap[E] = f;
    flow[E] = 0;
    to[E] = y;
    prev[E] = last[x];
    last[x] = E;
    E++;
    cap[E] = 0;
    flow[E] = 0;
    to[E] = x;
    prev[E] = last[y];
    last[y] = E;
    E++;
  }
  bool bfs(int s, int t) {
    int i;
    for (int(i) = 0; (i) < (int)(V); (i)++) level[i] = -1;
    queue<int> q;
    q.push(s);
    level[s] = 0;
    while (!q.empty()) {
      int x = q.front();
      q.pop();
      for (i = last[x]; i >= 0; i = prev[i])
        if (level[to[i]] == -1 && cap[i] > flow[i]) {
          q.push(to[i]);
          level[to[i]] = level[x] + 1;
        }
    }
    return (level[t] != -1);
  }
  int dfs(int v, int t, int f) {
    int i;
    if (v == t) return f;
    for (i = used[v]; i >= 0; used[v] = i = prev[i])
      if (level[to[i]] > level[v] && cap[i] > flow[i]) {
        int tmp = dfs(to[i], t, min(f, cap[i] - flow[i]));
        if (tmp > 0) {
          flow[i] += tmp;
          flow[i ^ 1] -= tmp;
          return tmp;
        }
      }
    return 0;
  }
  vector<pair<int, int> > positive_edges() {
    vector<pair<int, int> > ans;
    for (int(i) = 0; (i) < (int)(V); (i)++)
      for (int j = last[i]; j >= 0; j = prev[j])
        if (cap[j] - flow[j] > 0) ans.push_back(make_pair(i, to[j]));
    return ans;
  }
  int maxflow(int s, int t) {
    while (bfs(s, t)) {
      for (int(i) = 0; (i) < (int)(V); (i)++) used[i] = last[i];
      while (dfs(s, t, (1 << 29)) != 0)
        ;
    }
    int ans = 0;
    for (int i = last[s]; i >= 0; i = prev[i]) ans += flow[i];
    return ans;
  }
};
int h, l[55], r[55], x[55], c[55];
void fmain(int tid) {
  scanf("%d%d%d", &n, &h, &m);
  for (int(i) = 1; (i) <= (int)(m); (i)++)
    scanf("%d%d%d%d", l + i, r + i, x + i, c + i);
  int S = 0, T = (h + 1) * n + 1;
  MaxFlow mf = MaxFlow(T + 5 + m);
  int cur = 1;
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    int st = 1 + (h + 1) * (i - 1);
    mf.add_edge(S, st, (1 << 30));
    for (int z = 0; z < h; z++) {
      mf.add_edge(st + z, st + z + 1, h * h - z * z);
    }
    mf.add_edge(st + h, T, 0);
  }
  for (int(i) = 1; (i) <= (int)(m); (i)++)
    if (x[i] < h) {
      int y = T + i;
      mf.add_edge(y, T, c[i]);
      for (int j = l[i]; j <= r[i]; j++) {
        mf.add_edge(1 + (h + 1) * (j - 1) + x[i] + 1, y, (1 << 30));
      }
    }
  int ans = mf.maxflow(S, T);
  printf("%d\n", h * h * n - ans);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
