#include <bits/stdc++.h>
using namespace std;
int const INF = (int)1e9 + 1e3;
long long const INFL = (long long)1e18 + 1e6;
mt19937 tw(9450189);
uniform_int_distribution<long long> ll_distr;
long long rnd(long long a, long long b) {
  return ll_distr(tw) % (b - a + 1) + a;
}
void solve() {
  int n, k, m;
  cin >> n >> k >> m;
  vector<pair<int, int>> plans;
  vector<pair<int, int>> acts;
  for (int i = 0; i < m; ++i) {
    int l, r, c, p;
    cin >> l >> r >> c >> p;
    --l;
    acts.push_back({l, i});
    acts.push_back({r, i});
    plans.push_back({c, p});
  }
  vector<int> order(m);
  iota(order.begin(), order.end(), 0);
  sort(order.begin(), order.end(),
       [&](int a, int b) { return plans[a].second < plans[b].second; });
  vector<int> where(m);
  for (int i = 0; i < m; ++i) {
    where[order[i]] = i;
  }
  sort(acts.begin(), acts.end());
  int bpv = 1;
  while (bpv < m) {
    bpv *= 2;
  }
  vector<pair<long long, long long>> rsq(bpv * 2);
  function<void(int, long long, long long)> segtree_set =
      [&](int pos, long long val1, long long val2) {
        pos += bpv;
        rsq[pos] = {val1, val2};
        pos /= 2;
        while (pos) {
          rsq[pos] = {rsq[pos * 2].first + rsq[pos * 2 + 1].first,
                      rsq[pos * 2].second + rsq[pos * 2 + 1].second};
          pos /= 2;
        }
      };
  function<pair<int, pair<long long, long long>>(int, int, int, int)>
      segtree_find = [&](int v, int vl, int vr, int sz) {
        if (rsq[v].first <= sz) {
          return make_pair(vr, rsq[v]);
        }
        if (vl + 1 == vr) {
          return make_pair(vl, make_pair(0ll, 0ll));
        }
        int vm = (vl + vr) / 2;
        auto tmp = segtree_find(v * 2, vl, vm, sz);
        if (tmp.first < vm) {
          return tmp;
        }
        auto tmp2 = segtree_find(v * 2 + 1, vm, vr, sz - tmp.second.first);
        return make_pair(tmp2.first,
                         make_pair(tmp.second.first + tmp2.second.first,
                                   tmp.second.second + tmp2.second.second));
      };
  int c = 0;
  vector<bool> state(m);
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    while (c < ((int)acts.size()) && acts[c].first == i) {
      int ind = acts[c].second;
      if (state[ind]) {
        segtree_set(where[ind], 0, 0);
      } else {
        segtree_set(where[ind], plans[ind].first,
                    (long long)plans[ind].first * plans[ind].second);
      }
      state[ind] = state[ind] ^ 1;
      ++c;
    }
    auto tmp = segtree_find(1, 0, bpv, k);
    ans += tmp.second.second;
    if (tmp.first < bpv && tmp.second.first < k) {
      ans += (long long)(k - tmp.second.first) * plans[order[tmp.first]].second;
    }
  }
  cout << ans << "\n";
}
int main() {
  cout << setprecision(15) << fixed;
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int test_count = 1;
  for (int test = 1; test <= test_count; ++test) {
    solve();
  }
}
