#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
const int INF = 0x3f3f3f3f;
const long long mod = 998244353;
long long n, k, m;
vector<pair<long long, long long> > a[maxn];
struct tree {
  long long l, r;
  long long cnt, sum;
} tr[maxn << 2];
void build(long long id, long long l, long long r) {
  tr[id].l = l, tr[id].r = r;
  if (l == r) {
    tr[id].cnt = tr[id].sum = 0;
    return;
  }
  long long mid = (l + r) >> 1;
  build(id << 1, l, mid);
  build(id << 1 | 1, mid + 1, r);
}
void push_up(long long id) {
  tr[id].cnt = tr[id << 1].cnt + tr[id << 1 | 1].cnt;
  tr[id].sum = tr[id << 1].sum + tr[id << 1 | 1].sum;
}
void update(long long id, long long l, long long r, long long c) {
  long long l_ = tr[id].l, r_ = tr[id].r;
  if (l == l_ && r == r_) {
    tr[id].cnt += c;
    tr[id].sum += (c * (long long)r);
    return;
  }
  long long mid = (l_ + r_) >> 1;
  if (r <= mid) {
    update(id << 1, l, r, c);
  } else {
    update(id << 1 | 1, l, r, c);
  }
  push_up(id);
}
long long query(long long id, long long x) {
  if (tr[id].cnt <= x) return tr[id].sum;
  long long l = tr[id].l, r = tr[id].r;
  if (l == r) {
    long long t = min(x, tr[id].cnt);
    return (t * r);
  }
  if (tr[id << 1].cnt > x) return query(id << 1, x);
  return (query(id << 1, tr[id << 1].cnt) +
          query(id << 1 | 1, x - tr[id << 1].cnt));
}
int main() {
  scanf("%lld%lld%lld", &n, &k, &m);
  long long l, r, c, p, ans = 0;
  for (int i = 1; i <= m; ++i) {
    scanf("%lld%lld%lld%lld", &l, &r, &c, &p);
    a[l].push_back(pair<long long, long long>(c, p));
    a[r + 1].push_back(pair<long long, long long>(c * -1LL, p));
  }
  build(1, 1, maxn - 1);
  for (int i = 1; i <= n; ++i) {
    for (auto x : a[i]) {
      update(1, x.second, x.second, x.first);
    }
    ans += query(1, k);
  }
  printf("%lld", ans);
  return 0;
}
