#include <bits/stdc++.h>
using namespace std;
long long n, k, m, ind = 0;
long long res = 0;
vector<long long> bit;
vector<long long> price;
vector<vector<long long> > mat;
long long queryS(long long pos) {
  long long sum = 0;
  for (int i = pos; i >= 0; i = (i & (i + 1)) - 1) {
    sum += price[i];
  }
  return sum;
}
long long query(long long pos) {
  long long sum = 0;
  for (int i = pos; i >= 0; i = (i & (i + 1)) - 1) {
    sum += bit[i];
  }
  return sum;
}
long long find() {
  long long l = 0, r = bit.size() - 1, m, temp;
  while (r >= l) {
    m = (l + r) / 2;
    if (query(m) >= k)
      r = m - 1;
    else
      l = m + 1;
  }
  temp = bit.size() - 1;
  l = min(temp, l);
  long long cant = query(l);
  temp = 0;
  long long tot = queryS(l) - (max(temp, cant - k) * l);
  return tot;
}
void update(long long pos, long long cnt) {
  long long temp = cnt * pos;
  for (int i = pos; i < bit.size(); i = i | (i + 1)) {
    bit[i] += cnt;
    price[i] += temp;
  }
}
long long getAns(int day) {
  while (ind < mat.size() && mat[ind][0] <= day) {
    update(mat[ind][2], mat[ind][1]);
    ind++;
  }
  if (ind == mat.size()) return 0;
  return find();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k >> m;
  for (int i = 0; i < m; i++) {
    int l, r, c, p;
    cin >> l >> r >> c >> p;
    mat.push_back({l, c, p});
    mat.push_back({r + 1, -c, p});
  }
  sort(mat.begin(), mat.end());
  bit = vector<long long>(1000006, 0);
  price = vector<long long>(1000006, 0);
  for (int i = 1; i < n + 1; i++) {
    res += getAns(i);
  }
  cout << res << endl;
  ;
}
