#include <bits/stdc++.h>
using namespace std;
int64_t n, k, m, ans, s, fen[2][200001];
vector<int64_t> L[1000001], R[1000001];
pair<pair<int64_t, int64_t>, pair<int64_t, int64_t> > v[200001];
void upd(int64_t i, int64_t v, int64_t j) {
  for (; i <= m; i += i & -i) fen[j][i] += v;
}
int64_t que(int64_t i, int64_t j) {
  for (s = 0; i; i -= i & -i) s += fen[j][i];
  return s;
}
int64_t help() {
  int64_t st = 1, en = m, md, ans, id = m, tmp, ret;
  while (st <= en) {
    md = (st + en) / 2;
    tmp = que(md, 0);
    if (tmp >= k)
      id = md, ans = tmp, en = md - 1;
    else
      st = md + 1;
  }
  if (id == m) ans = que(m, 0);
  return ans > k ? (k - que(id - 1, 0)) * v[id].first.first + que(id - 1, 1)
                 : que(id, 1);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k >> m;
  for (int64_t i = 1; i <= m; ++i)
    cin >> v[i].second.first >> v[i].second.second >> v[i].first.second >>
        v[i].first.first;
  sort(v + 1, v + m + 1);
  for (int64_t i = 1; i <= m; ++i) {
    L[v[i].second.first].push_back(i);
    R[v[i].second.second].push_back(i);
  }
  for (int64_t i = 1; i <= n; ++i) {
    for (int64_t j : L[i])
      upd(j, v[j].first.second, 0),
          upd(j, v[j].first.first * v[j].first.second, 1);
    ans += help();
    for (int64_t j : R[i])
      upd(j, -v[j].first.second, 0),
          upd(j, -v[j].first.first * v[j].first.second, 1);
  }
  cout << ans;
}
