#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
pair<long long, long long> bit[N];
pair<long long, long long> get(int idx) {
  pair<long long, long long> res = pair<long long, long long>(0, 0);
  while (idx) {
    res.first += bit[idx].first;
    res.second += bit[idx].second;
    idx -= idx & -idx;
  }
  return res;
}
void upd(int idx, pair<long long, long long> del) {
  while (idx < N) {
    bit[idx].first += del.first;
    bit[idx].second += del.second;
    idx += idx & -idx;
  }
}
map<int, vector<int> > aux;
int main() {
  int n, k, m;
  scanf("%d %d %d", &n, &k, &m);
  vector<pair<int, pair<int, pair<int, int> > > > v;
  for (int i = 0; i < m; i++) {
    int li, ri, ci, pi;
    scanf("%d %d %d %d", &li, &ri, &ci, &pi);
    v.push_back({pi, {ci, {li, ri}}});
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < m; i++) {
    int idx = i + 1;
    pair<int, int> rang = v[i].second.second;
    aux[rang.first].push_back(idx);
    aux[rang.second + 1].push_back(-idx);
  }
  long long ans = 0;
  long long last = 0;
  for (int i = 1; i <= n; i++) {
    if (aux[i].size() == 0) {
      ans += last;
      continue;
    }
    for (int idx : aux[i]) {
      bool flag = 0;
      if (idx < 0) flag = 1, idx *= -1;
      long long cn = v[idx - 1].second.first;
      long long p = v[idx - 1].first;
      if (flag)
        upd(idx, pair<long long, long long>(-cn, -cn * p));
      else
        upd(idx, pair<long long, long long>(cn, cn * p));
    }
    int low = 0, high = m;
    while (high - low > 1) {
      int mid = (high + low) / 2;
      if (get(mid).first >= k)
        high = mid;
      else
        low = mid;
    }
    pair<long long, long long> res = get(high);
    long long aux = res.first - k;
    if (aux < 0) aux = 0;
    last = res.second - (aux)*v[high - 1].first;
    ans += last;
  }
  printf("%lld\n", ans);
  return 0;
}
