#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const long long MAXN = 1e6 + 7;
const double EPS = 1e-8;
pair<long long, long long> rmq[4 * MAXN];
struct Event {
  long long type;
  long long day;
  long long cost;
  long long qnt;
};
bool cmp(Event &a, Event &b) { return (a.day < b.day); }
void change(long long i, long long l, long long r, long long c, long long q) {
  if (r - l == 1) {
    rmq[i].first += q;
    rmq[i].second += q * l;
    return;
  }
  long long mid = (l + r) / 2;
  if (c < mid)
    change(2 * i + 1, l, mid, c, q);
  else
    change(2 * i + 2, mid, r, c, q);
  rmq[i].first = rmq[2 * i + 1].first + rmq[2 * i + 2].first;
  rmq[i].second = rmq[2 * i + 1].second + rmq[2 * i + 2].second;
}
long long ans = 0;
void request(long long i, long long l, long long r, long long k) {
  if (r - l == 1) {
    long long kek = min(k, rmq[i].first);
    ans += kek * l;
    return;
  }
  long long S = rmq[2 * i + 1].first;
  long long mid = (l + r) / 2;
  if (S >= k) {
    request(2 * i + 1, l, mid, k);
    return;
  }
  ans += rmq[2 * i + 1].second;
  request(2 * i + 2, mid, r, k - S);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k, m;
  cin >> n >> k >> m;
  vector<Event> ev;
  for (long long i = 0; i < m; i++) {
    long long l, r, c, p;
    cin >> l >> r >> c >> p;
    ev.push_back({0, l - 1, p, c});
    ev.push_back({1, r, p, c});
  }
  sort(ev.begin(), ev.end(), cmp);
  for (long long i = 0; i < MAXN; i++) rmq[i] = {0, 0};
  long long u = 0;
  for (long long i = 0; i < n; i++) {
    while (u < 2 * m && ev[u].day == i) {
      if (ev[u].type == 0)
        change(0, 0, MAXN, ev[u].cost, ev[u].qnt);
      else
        change(0, 0, MAXN, ev[u].cost, -ev[u].qnt);
      u++;
    }
    request(0, 0, MAXN, k);
  }
  cout << ans;
}
