#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
template <class T>
inline bool MX(T &l, const T &r) {
  return l < r ? l = r, 1 : 0;
}
template <class T>
inline bool MN(T &l, const T &r) {
  return l > r ? l = r, 1 : 0;
}
long long sum(const vector<long long> &bit, int i) {
  ++i;
  long long s = 0;
  while (i > 0) {
    s += bit[i];
    i -= i & -i;
  }
  return s;
}
void add(vector<long long> &bit, int i, long long x) {
  ++i;
  while (i < bit.size()) {
    bit[i] += x;
    i += i & -i;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(0);
  int n, t, m;
  cin >> n >> t >> m;
  vector<vector<pair<int, int>>> ad(n + 1);
  for (int(i) = (0); (i) < (m); ++(i)) {
    int l, r, c, p;
    cin >> l >> r >> c >> p;
    --l;
    ad[l].emplace_back(p, c);
    ad[r].emplace_back(p, -c);
  }
  const int N = 1000100;
  vector<long long> sz(N), cost(N);
  long long re = 0;
  for (int(i) = (0); (i) < (n); ++(i)) {
    for (pair<int, int> p : ad[i]) {
      add(sz, p.first, p.second);
      add(cost, p.first, 1ll * p.first * p.second);
    }
    if (sum(sz, N) <= t) {
      re += sum(cost, N);
      continue;
    }
    int l = 0, r = N;
    while (r - l > 1) {
      int m = (l + r) / 2;
      (sum(sz, m) > t ? r : l) = m;
    }
    re += sum(cost, l);
    re += r * (t - sum(sz, l));
  }
  cout << re << endl;
  return 0;
}
