#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long n;
long long fen[1000000 + 10];
long long fen1[1000000 + 10];
void update(long long p, long long val) {
  for (long long i = p; i <= n; i += i & -i) fen[i] += val;
}
long long sum(long long p) {
  long long ans = 0;
  for (long long i = p; i; i -= i & -i) ans += fen[i];
  return ans;
}
void update1(long long p, long long val) {
  for (long long i = p; i <= n; i += i & -i) fen1[i] += val;
}
long long sum1(long long p) {
  long long ans = 0;
  for (long long i = p; i; i -= i & -i) ans += fen1[i];
  return ans;
}
long long n1, k;
vector<pair<long long, pair<long long, long long> > > start[1000000 + 10];
vector<pair<long long, pair<long long, long long> > > fin[1000000 + 10];
vector<pair<long long, pair<long long, pair<long long, long long> > > > values;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n1 >> k >> n;
  long long l, r, c, p;
  for (long long i = 0; i < n; i++) {
    cin >> l >> r >> c >> p;
    values.push_back(make_pair(p, make_pair(c, make_pair(l, r))));
  }
  sort(values.begin(), values.end());
  for (long long i = 0; i < n; i++) {
    start[values[i].second.second.first].push_back(
        make_pair(i + 1, make_pair(values[i].first, values[i].second.first)));
    fin[values[i].second.second.second + 1].push_back(
        make_pair(i + 1, make_pair(values[i].first, values[i].second.first)));
  }
  long long ans = 0;
  for (long long i = 1; i < n1 + 1; i++) {
    for (auto it = fin[i].begin(); it != fin[i].end(); it++) {
      update((*it).first, -1 * (*it).second.second);
      update1((*it).first, -1 * (*it).second.second * (*it).second.first);
    }
    for (auto it = start[i].begin(); it != start[i].end(); it++) {
      update((*it).first, (*it).second.second);
      update1((*it).first, (*it).second.second * (*it).second.first);
    }
    long long lo = 1, hi = n;
    if (sum(hi) <= k) {
      ans += sum1(hi);
    } else if (sum(lo) > k) {
      ans += (k * values[0].first);
    } else {
      while (hi - lo > 1) {
        long long mid = (lo + hi) / 2;
        if (sum(mid) <= k) {
          lo = mid;
        } else {
          hi = mid;
        }
      }
      ans += (sum1(lo));
      ans += ((k - sum(lo)) * values[hi - 1].first);
    }
  }
  cout << ans << '\n';
  return 0;
}
