#include <bits/stdc++.h>
using namespace std;
struct info {
  int po, c, p;
  info() {}
  info(int a, int b, int d) : po(a), c(b), p(d) {}
  friend bool operator<(info a, info b) { return a.po < b.po; }
} A[4000010];
long long Ans, tmp, n, k, m;
int tp;
namespace Seg {
long long T[4000010], sum[4000010];
void upd(int l, int r, int id, int p, int c) {
  if (l == r) {
    T[id] += c, sum[id] += c * 1ll * p;
    return;
  }
  int mid = (l + r) >> 1;
  if (p <= mid)
    upd(l, mid, id << 1, p, c);
  else
    upd(mid + 1, r, id << 1 | 1, p, c);
  T[id] = T[id << 1] + T[id << 1 | 1];
  sum[id] = sum[id << 1] + sum[id << 1 | 1];
}
long long Q(int l, int r, int id, int p) {
  if (l == r) return min((long long)p, T[id]) * 1ll * l;
  int mid = (l + r) >> 1;
  long long res = 0;
  if (T[id << 1] >= p)
    res = Q(l, mid, id << 1, p);
  else
    res = sum[id << 1] + Q(mid + 1, r, id << 1 | 1, p - T[id << 1]);
  return res;
}
}  // namespace Seg
using namespace Seg;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int main() {
  n = read(), k = read(), m = read();
  for (int i = 1; i <= m; ++i) {
    int l = read(), r = read(), c = read(), p = read();
    A[++tp] = info(l, c, p), A[++tp] = info(r + 1, -c, p);
  }
  sort(A + 1, A + tp + 1);
  int p = 1;
  for (int i = 1; i <= n; ++i) {
    int pre = p;
    for (; A[p].po == i && p <= tp; ++p) upd(1, 1e6, 1, A[p].p, A[p].c);
    if (pre != p) tmp = Q(1, 1e6, 1, k);
    Ans += tmp;
  }
  printf("%lld\n", Ans);
  return 0;
}
