#include <bits/stdc++.h>
using namespace std;
inline int read();
const int N = 1e6 + 5;
int n, m, k, tot;
struct P {
  int d, c, p;
  bool operator<(const P& a) const { return d < a.d; }
} a[N << 1];
long long ans;
namespace Seg {
struct P {
  int l, r;
  long long c, sum;
} f[N << 2];
void build(int x, int l, int r) {
  f[x] = {l, r, 0, 0};
  if (l == r) return;
  int mid = l + r >> 1;
  build((x << 1), l, mid);
  build((x << 1 | 1), mid + 1, r);
}
void modify(int x, int sit, int val) {
  if (f[x].l == f[x].r) {
    f[x].c += val;
    f[x].sum += 1ll * f[x].l * val;
    return;
  }
  int mid = f[x].l + f[x].r >> 1;
  if (sit <= mid)
    modify((x << 1), sit, val);
  else
    modify((x << 1 | 1), sit, val);
  f[x].c = f[(x << 1)].c + f[(x << 1 | 1)].c;
  f[x].sum = f[(x << 1)].sum + f[(x << 1 | 1)].sum;
}
long long query(int x, int res) {
  if (f[x].l == f[x].r) return 1ll * f[x].l * min(f[x].c, 1ll * res);
  if (res <= f[(x << 1)].c) return query((x << 1), res);
  return f[(x << 1)].sum + query((x << 1 | 1), res - f[(x << 1)].c);
}
}  // namespace Seg
int main() {
  n = read(), k = read(), m = read();
  int l, r, c, p;
  for (register int i = (1); i <= (m); ++i) {
    l = read(), r = read(), c = read(), p = read();
    a[++tot] = {l, c, p};
    a[++tot] = {r + 1, -c, p};
  }
  sort(a + 1, a + tot + 1);
  Seg::build(1, 1, 1e6);
  int cur = 1;
  for (register int i = (1); i <= (n); ++i) {
    while (cur <= tot and a[cur].d <= i)
      Seg::modify(1, a[cur].p, a[cur].c), ++cur;
    ans += Seg::query(1, k);
  }
  printf("%lld", ans);
  return 0;
}
inline int read() {
  register int x = 0;
  register char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return x;
}
