#include <bits/stdc++.h>
using namespace std;
long long _gcd(long long a, long long b) { return b == 0 ? a : _gcd(b, a % b); }
long long gcd(long long a, long long b) { return _gcd(abs(a), abs(b)); }
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m, k;
  cin >> n >> k >> m;
  tuple<long long, long long, long long, long long> off[m];
  for (long long i = 0; i < m; i++) {
    long long l, r, c, p;
    cin >> l >> r >> c >> p;
    off[i] = make_tuple(l, r, c, p);
  }
  sort(off, off + m);
  multiset<tuple<long long, long long, long long>,
           greater<tuple<long long, long long, long long> > >
      use;
  multiset<tuple<long long, long long, long long> > dis;
  long long tot = 0;
  long long cost = 0;
  long long ans = 0;
  multiset<tuple<long long, long long, long long> > rem;
  long long ll = 0;
  long long j = 0;
  for (long long i = 1; i <= n; i++) {
    while (!rem.empty()) {
      long long re, pe, ide;
      tie(re, pe, ide) = *rem.begin();
      if (re >= i) break;
      set<tuple<long long, long long, long long> >::iterator it;
      while (it = use.lower_bound(make_tuple(pe, ide, (long long)1e9)),
             it != use.end() && get<1>(*it) == ide) {
        long long dp, did, dx;
        tie(dp, did, dx) = *it;
        use.erase(it);
        cost -= dx * dp;
        tot -= dx;
      }
      while (it = dis.lower_bound(make_tuple(pe, ide, 0)),
             it != dis.end() && get<1>(*it) == ide) {
        dis.erase(it);
      }
      rem.erase(rem.begin());
    }
    for (; j < m; j++) {
      long long l, r, c, p;
      tie(l, r, c, p) = off[j];
      if (l > i) break;
      dis.insert(make_tuple(p, j, c));
      rem.insert(make_tuple(r, p, j));
    }
    while (tot < k && !dis.empty()) {
      set<tuple<long long, long long, long long> >::iterator it = dis.begin();
      long long dp, did, dx;
      tie(dp, did, dx) = *it;
      if (dx > k - tot) {
        long long put = k - tot;
        use.insert(make_tuple(dp, did, put));
        cost += (put)*dp;
        tot += (put);
        dis.erase(it);
        dis.insert(make_tuple(dp, did, dx - (put)));
      } else {
        use.insert(make_tuple(dp, did, dx));
        cost += dx * dp;
        tot += dx;
        dis.erase(it);
      }
    }
    while (!use.empty() && !dis.empty()) {
      long long up, uid, ux;
      tie(up, uid, ux) = *use.begin();
      long long dp, did, dx;
      tie(dp, did, dx) = *dis.begin();
      if (up <= dp) break;
      if (dx > ux) {
        use.erase(use.begin());
        cost -= ux * up;
        tot -= ux;
        dis.erase(dis.begin());
        use.insert(make_tuple(dp, did, ux));
        cost += ux * dp;
        tot += ux;
        dis.insert(make_tuple(dp, did, dx - ux));
        dis.insert(make_tuple(up, uid, ux));
      } else {
        use.erase(use.begin());
        cost -= ux * up;
        tot -= ux;
        dis.erase(dis.begin());
        use.insert(make_tuple(dp, did, dx));
        cost += dx * dp;
        tot += dx;
        if (ux - dx > 0) use.insert(make_tuple(up, uid, ux - dx));
        cost += (ux - dx) * up;
        tot += (ux - dx);
        dis.insert(make_tuple(up, uid, dx));
      }
    }
    ans += cost;
  }
  cout << ans << endl;
}
