#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,mmx,avx,tune=native")
using namespace std;
const int MOD = 1000000007;
const int UNDEF = -1;
const int INF = (1 << 30) - 2;
template <typename T>
inline bool chkmax(T& aa, T bb) {
  return aa < bb ? aa = bb, true : false;
}
template <typename T>
inline bool chkmin(T& aa, T bb) {
  return aa > bb ? aa = bb, true : false;
}
int rint();
char rch();
long long rlong();
class Dinic {
 public:
  const int DINF = INF;
  struct edge {
    int a, b;
    int cap, flow;
  };
  int dinic_numnodes, dinic_src, dinic_dest;
  vector<int> d, ptr, q;
  vector<edge> dinic_edge;
  vector<vector<int> > dinic_graph;
  void add_edge(int a, int b, int cap) {
    int c = max(a, b);
    if (c >= (int)dinic_graph.size()) dinic_graph.resize(c + 1);
    edge e1 = {a, b, cap, 0};
    edge e2 = {b, a, 0, 0};
    dinic_graph[a].push_back((int)dinic_edge.size());
    dinic_edge.push_back(e1);
    dinic_graph[b].push_back((int)dinic_edge.size());
    dinic_edge.push_back(e2);
  }
  bool dinic_bfs() {
    int qh = 0, qt = 0;
    q[qt++] = dinic_src;
    fill(d.begin(), d.end(), -1);
    d[dinic_src] = 0;
    while (qh < qt && d[dinic_dest] == -1) {
      int v = q[qh++];
      for (size_t i = 0; i < dinic_graph[v].size(); ++i) {
        int id = dinic_graph[v][i], to = dinic_edge[id].b;
        if (d[to] == -1 && dinic_edge[id].flow < dinic_edge[id].cap) {
          q[qt++] = to;
          d[to] = d[v] + 1;
        }
      }
    }
    return d[dinic_dest] != -1;
  }
  int dinic_dfs(int v, int flow) {
    if (!flow) return 0;
    if (v == dinic_dest) return flow;
    for (; ptr[v] < (int)dinic_graph[v].size(); ++ptr[v]) {
      int id = dinic_graph[v][ptr[v]], to = dinic_edge[id].b;
      if (d[to] != d[v] + 1) continue;
      int pushed =
          dinic_dfs(to, min(flow, dinic_edge[id].cap - dinic_edge[id].flow));
      if (pushed) {
        dinic_edge[id].flow += pushed;
        dinic_edge[id ^ 1].flow -= pushed;
        return pushed;
      }
    }
    return 0;
  }
  int get_flow(int src, int dest, int numnodes = -1) {
    if (src == dest) return DINF;
    if (numnodes == -1)
      numnodes = max(max(src, dest) + 1, (int)dinic_graph.size());
    d.resize(numnodes);
    ptr.resize(numnodes);
    q.resize(numnodes);
    dinic_src = src;
    dinic_dest = dest;
    dinic_numnodes = numnodes;
    int flow = 0;
    for (;;) {
      if (!dinic_bfs()) break;
      fill(ptr.begin(), ptr.end(), 0);
      while (int pushed = dinic_dfs(dinic_src, DINF)) flow += pushed;
    }
    return flow;
  }
  void reset(int numnodes = -1) {
    if (numnodes == -1) numnodes = (int)dinic_graph.size();
    dinic_edge.clear();
    for (int v = 0; v < numnodes; v++) dinic_graph[v].clear();
  }
};
Dinic D;
int n, hlim, m;
int posH(int pos, int h) {
  ;
  return m + (pos - 1) * hlim + (h - 1);
}
int con(int c) { return c; }
void assert_unique(vector<int> v) {
  sort(v.begin(), v.end());
  for (int i = 1; i < v.size(); i++)
    ;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  n = rint(), hlim = rint(), m = rint();
  int src = posH(n, hlim) + 1;
  int dest = src + 1;
  {
    vector<int> tmp;
    for (int pos = 1; pos <= n; pos++)
      for (int h = 1; h <= hlim; h++) tmp.push_back(posH(pos, h));
    for (int c = 0; c < m; c++) tmp.push_back(con(c));
    tmp.push_back(src);
    tmp.push_back(dest);
    assert_unique(tmp);
  }
  for (int pos = 1; pos <= n; pos++) {
    for (int h = hlim; h >= 2; h--)
      D.add_edge(posH(pos, h), posH(pos, h - 1), INF);
    for (int h = hlim; h >= 1; h--) D.add_edge(src, posH(pos, h), 2 * h - 1);
  }
  for (int c = 0; c < m; c++) {
    int l = rint(), r = rint(), x = rint(), cost = rint();
    if (x + 1 > hlim) continue;
    for (int pos = l; pos <= r; pos++) {
      D.add_edge(posH(pos, x + 1), con(c), INF);
    }
    D.add_edge(con(c), dest, cost);
  }
  int f = D.get_flow(src, dest);
  int all = n * (hlim * hlim);
  int ans = all - f;
  printf("%d\n", ans);
}
static char stdinBuffer[1024];
static char* stdinDataEnd = stdinBuffer + sizeof(stdinBuffer);
static const char* stdinPos = stdinDataEnd;
void readAhead(size_t amount) {
  size_t remaining = stdinDataEnd - stdinPos;
  if (remaining < amount) {
    memmove(stdinBuffer, stdinPos, remaining);
    size_t sz = fread(stdinBuffer + remaining, 1,
                      sizeof(stdinBuffer) - remaining, stdin);
    stdinPos = stdinBuffer;
    stdinDataEnd = stdinBuffer + remaining + sz;
    if (stdinDataEnd != stdinBuffer + sizeof(stdinBuffer)) *stdinDataEnd = 0;
  }
}
int rint() {
  readAhead(16);
  int x = 0;
  bool neg = false;
  while (*stdinPos == ' ' || *stdinPos == '\n') ++stdinPos;
  if (*stdinPos == '-') {
    ++stdinPos;
    neg = true;
  }
  while (*stdinPos >= '0' && *stdinPos <= '9') {
    x *= 10;
    x += *stdinPos - '0';
    ++stdinPos;
  }
  return neg ? -x : x;
}
char rch() {
  readAhead(16);
  while (*stdinPos == ' ' || *stdinPos == '\n') ++stdinPos;
  char ans = *stdinPos;
  ++stdinPos;
  return ans;
}
long long rlong() {
  readAhead(32);
  long long x = 0;
  bool neg = false;
  while (*stdinPos == ' ' || *stdinPos == '\n') ++stdinPos;
  if (*stdinPos == '-') {
    ++stdinPos;
    neg = true;
  }
  while (*stdinPos >= '0' && *stdinPos <= '9') {
    x *= 10;
    x += *stdinPos - '0';
    ++stdinPos;
  }
  return neg ? -x : x;
}
