#include <bits/stdc++.h>
using namespace std;
long long n, k, m, l, r, c, p, ans;
vector<long long> cnt[1000005], val[1000005];
struct BIT {
  long long tree[1000005];
  BIT() {
    memset(tree, 0, sizeof(tree));
    return;
  }
  inline long long lowbit(long long x) { return x & (-x); }
  inline void add(long long pos, long long val) {
    while (pos <= 1000000) tree[pos] += val, pos += lowbit(pos);
    return;
  }
  inline long long ask(long long pos) {
    long long ans = 0;
    while (pos) ans += tree[pos], pos -= lowbit(pos);
    return ans;
  }
} bit1, bit2;
signed main() {
  cin >> n >> k >> m;
  for (long long i = 1; i <= m; i++) {
    scanf("%lld%lld%lld%lld", &l, &r, &c, &p);
    cnt[l].push_back(c), val[l].push_back(p);
    cnt[r + 1].push_back(-c), val[r + 1].push_back(p);
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0, len = cnt[i].size(); j < len; j++) {
      bit1.add(val[i][j], cnt[i][j]);
      bit2.add(val[i][j], val[i][j] * cnt[i][j]);
    }
    long long l = 1, r = 1000000, now = 1000000;
    while (l <= r) {
      long long mid = (l + r) / 2;
      if (bit1.ask(mid) >= k)
        now = mid, r = mid - 1;
      else
        l = mid + 1;
    }
    if (bit1.ask(now) > k)
      ans += bit2.ask(now) - (bit1.ask(now) - k) * now;
    else
      ans += bit2.ask(now);
  }
  cout << ans << endl;
  return 0;
}
