#include <bits/stdc++.h>
using namespace std;
template <typename T = int>
struct BIT {
  vector<T> ft;
  BIT(int n) : ft(n + 2, 0) {}
  void update(int pos, T val) {
    while (pos < int(ft.size())) {
      ft[pos] += val;
      pos += pos & -pos;
    }
  }
  void update(int l, int r, T val) {
    if (l > r) return;
    update(l, val);
    update(r + 1, -val);
  }
  T sum(int pos) {
    T ret = 0;
    while (pos) {
      ret += ft[pos];
      pos -= pos & -pos;
    }
    return ret;
  }
  T sum(int l, int r) {
    if (l > r) return 0;
    return sum(r) - sum(l - 1);
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k, m;
  cin >> n >> k >> m;
  struct Plan {
    int l, r, c, p;
    bool operator<(const Plan& other) const { return p < other.p; }
  };
  vector<Plan> plan;
  for (int i = 0; i < m; i++) {
    int l, r, c, p;
    cin >> l >> r >> c >> p;
    plan.push_back(Plan{l, r, c, p});
  }
  struct Event {
    int t, c, p, i;
    bool operator<(const Event& other) const { return t > other.t; }
  };
  vector<Event> open(m);
  vector<Event> close(m);
  sort(begin(plan), end(plan));
  for (int i = 0; i < m; i++) {
    open[i] = Event{plan[i].l, plan[i].c, plan[i].p, i + 1};
    close[i] = Event{plan[i].r, plan[i].c, plan[i].p, i + 1};
  }
  sort(begin(open), end(open));
  sort(begin(close), end(close));
  BIT<long long> s1(m + 1);
  BIT<long long> s2(m + 1);
  long long ans = 0;
  for (int day = 1; day <= n; day++) {
    while (not open.empty() and open.back().t == day) {
      s1.update(open.back().i, open.back().c);
      s2.update(open.back().i, 1LL * open.back().c * open.back().p);
      open.pop_back();
    }
    if (s1.sum(1, m) <= k) {
      ans += s2.sum(1, m);
    } else {
      int lo = 1, hi = m;
      while (lo != hi) {
        int mid = (lo + hi) >> 1;
        if (s1.sum(1, mid) > k)
          hi = mid;
        else
          lo = mid + 1;
      }
      ans += s2.sum(1, lo - 1);
      ans += (k - s1.sum(1, lo - 1)) * plan[lo - 1].p;
    }
    while (not close.empty() and close.back().t == day) {
      s1.update(close.back().i, -close.back().c);
      s2.update(close.back().i, -1LL * close.back().c * close.back().p);
      close.pop_back();
    }
  }
  cout << ans << '\n';
  return (0);
}
