#include <bits/stdc++.h>
const int maxn = 1e6 + 3, lo = 0x100000;
long long n, k, m, l[maxn], r[maxn], c[maxn], p[maxn];
std::vector<int> pl[maxn], ql[maxn];
struct node {
  long long s, t;
} seg[lo * 2];
void modify(long long pri, long long cnt) {
  seg[pri + lo].s += cnt;
  seg[pri + lo].t += cnt * pri;
  for ((pri += lo) >>= 1; pri > 0; pri >>= 1) {
    seg[pri].s = seg[pri * 2].s + seg[pri * 2 + 1].s;
    seg[pri].t = seg[pri * 2].t + seg[pri * 2 + 1].t;
  }
}
long long query(long long need) {
  if (seg[1].s <= need) {
    return seg[1].t;
  }
  int p = 1;
  long long ans = 0;
  while (p < lo) {
    if (seg[p * 2].s >= need) {
      p = p * 2;
    } else {
      need -= seg[p * 2].s;
      ans += seg[p * 2].t;
      p = p * 2 + 1;
    }
  }
  ans += seg[p].t / seg[p].s * need;
  return ans;
}
int main() {
  scanf("%lld%lld%lld", &n, &k, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%lld%lld%lld%lld", l + i, r + i, c + i, p + i);
    pl[l[i]].push_back(i);
    ql[r[i]].push_back(i);
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (auto u : pl[i]) modify(p[u], c[u]);
    ans += query(k);
    for (auto u : ql[i]) modify(p[u], -c[u]);
  }
  printf("%lld\n", ans);
  return 0;
}
