#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
long long sumv[4 * maxn], minv[4 * maxn], maxv[4 * maxn];
long long setv[4 * maxn], addv[4 * maxn];
int n, k, m;
long long ans;
void pushup(int o) {
  sumv[o] = sumv[o * 2] + sumv[o * 2 + 1];
  maxv[o] = max(maxv[o * 2 + 1], maxv[o * 2]);
  minv[o] = min(minv[o * 2], minv[o * 2 + 1]);
}
void pushdown(int o, int L, int R) {
  int M = (L + R) >> 1;
  if (setv[o] != -1) {
    setv[o * 2] = setv[o * 2 + 1] = setv[o];
    addv[o * 2] = addv[o * 2 + 1] = 0;
    sumv[o * 2] = sumv[o * 2 + 1] = maxv[o * 2] = maxv[o * 2 + 1] =
        minv[o * 2] = minv[o * 2 + 1] = setv[o];
    setv[o] = -1;
  }
  if (addv[o] != 0) {
    addv[o * 2] += addv[o];
    addv[o * 2 + 1] += addv[o];
    minv[o * 2] += addv[o];
    minv[o * 2 + 1] += addv[o];
    sumv[o * 2] += addv[o] * (M - L + 1);
    sumv[o * 2 + 1] += addv[o] * (R - M);
    maxv[o * 2] += addv[o];
    maxv[o * 2 + 1] += addv[o];
    addv[o] = 0;
  }
}
void build(int o, int L, int R) {
  setv[o] = -1;
  if (L == R) {
    sumv[o] = minv[o] = maxv[o] = k;
    return;
  }
  int M = (L + R) >> 1;
  build(o * 2, L, M);
  build(o * 2 + 1, M + 1, R);
  pushup(o);
}
void update(int o, int L, int R, int ql, int qr, int p, int v) {
  if (ql <= L && R <= qr) {
    if (maxv[o] <= p) {
      ans += v * sumv[o];
      setv[o] = addv[o] = maxv[o] = minv[o] = sumv[o] = 0;
      return;
    } else if (minv[o] >= p) {
      ans += (long long)(R - L + 1) * p * v;
      addv[o] -= p;
      maxv[o] -= p;
      minv[o] -= p;
      sumv[o] -= (long long)(R - L + 1) * p;
      return;
    }
  }
  pushdown(o, L, R);
  int M = (L + R) >> 1;
  if (ql <= M) update(o * 2, L, M, ql, qr, p, v);
  if (qr > M) update(o * 2 + 1, M + 1, R, ql, qr, p, v);
  pushup(o);
}
struct node {
  int l, r, v, p;
  friend bool operator<(node a, node b) { return a.v < b.v; }
} q[200005];
int main() {
  cin >> n >> k >> m;
  build(1, 1, n);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d%d", &q[i].l, &q[i].r, &q[i].p, &q[i].v);
  }
  sort(q + 1, q + 1 + m);
  for (int i = 1; i <= m; i++) {
    update(1, 1, n, q[i].l, q[i].r, q[i].p, q[i].v);
  }
  cout << ans << endl;
  return 0;
}
