#include <bits/stdc++.h>
using namespace std;
struct Node {
  int from, to;
  Node *left = nullptr, *right = nullptr;
  long long cnt = 0;
  long long tot = 0;
  Node(int l, int r) : from(l), to(r) {
    if (from < to) {
      int mid = (from + to) / 2;
      left = new Node(from, mid);
      right = new Node(mid + 1, to);
    }
  }
  void upd(int i, long long c) {
    cnt += c;
    tot += c * i;
    if (from == to) {
      return;
    }
    int mid = (from + to) / 2;
    if (i <= mid) {
      left->upd(i, c);
    } else {
      right->upd(i, c);
    }
  }
  long long get(long long k) {
    if (from == to) {
      return min(k, cnt) * from;
    }
    if (left->cnt >= k) {
      return left->get(k);
    }
    return right->get(k - left->cnt) + left->tot;
  }
};
using Upd = pair<int, pair<int, int>>;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> k >> m;
  auto st = new Node(0, 1e6 + 1);
  vector<vector<pair<int, int>>> updates(n + 1);
  for (int i = 0; i < m; i++) {
    int l, r, cnt, p;
    cin >> l >> r >> cnt >> p;
    l--;
    r--;
    updates[l].push_back({cnt, p});
    updates[r + 1].push_back({-cnt, p});
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (auto upd : updates[i]) {
      st->upd(upd.second, upd.first);
    }
    ans += st->get(k);
  }
  cout << ans << endl;
  return 0;
}
