#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 5;
struct data {
  int l, r, c, p;
  data(int a, int b, int c, int d) { l = a, r = b, c = c, p = d; }
  bool operator<(const data &d) const {
    if (p < d.p) {
      return 1;
    }
    return 0;
  }
};
vector<pair<int, int> > st[N + 4], en[N + 4];
long long int BIT[2][N + 5];
void update(int id, int idx, long long int val) {
  while (idx < N) {
    BIT[id][idx] += val;
    idx += (idx & (-idx));
  }
}
long long int query(int id, int idx) {
  long long int sum = 0LL;
  while (idx > 0) {
    sum += BIT[id][idx];
    idx -= (idx & (-idx));
  }
  return sum;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  vector<data> V;
  int n, m, k;
  cin >> n >> k >> m;
  for (int i = 1; i <= m; i++) {
    int l, r, c, p;
    cin >> l >> r >> c >> p;
    data t(l, r, c, p);
    V.push_back(t);
    st[l].push_back({c, p});
    en[r + 1].push_back({c, p});
  }
  long long int ans = 0LL;
  for (int i = 1; i <= n; i++) {
    for (auto x : st[i]) {
      int idx = x.second;
      int amount = x.first;
      update(0, idx, amount);
      update(1, idx, 1LL * idx * amount);
    }
    for (auto x : en[i]) {
      int idx = x.second;
      int amount = x.first;
      update(0, idx, -amount);
      update(1, idx, (-1LL * idx * amount));
    }
    int lo = 0, hi = N;
    long long int lol = 0;
    int baki = 0;
    while (lo <= hi) {
      int mid = (lo + hi) >> 1;
      long long int val = query(0, mid);
      if (val <= k) {
        lol = mid;
        baki = k - val;
        lo = mid + 1;
      } else {
        hi = mid - 1;
      }
    }
    long long int temp = query(1, lol);
    if (lol == N) {
      ans += (temp);
      continue;
    }
    long long int X = temp + baki * (lol + 1);
    ans += X;
  }
  cout << ans << endl;
  return 0;
}
