#include <bits/stdc++.h>
using namespace std;
const long long maxn = 400005;
long long n, k, m, l[maxn], r[maxn], p[maxn], c[maxn], mx;
vector<long long> vec;
vector<pair<long long, long long> > op[maxn];
namespace Seg {
static const long long N = 1e6 + 5;
long long tr[N << 2], sum[N << 2];
inline void Update(long long o, long long l, long long r, long long p,
                   long long d) {
  if (l == r) {
    tr[o] += d;
    sum[o] += p * d;
    return;
  }
  if (p <= ((l + r) >> 1))
    Update(o << 1, l, ((l + r) >> 1), p, d);
  else
    Update(o << 1 | 1, ((l + r) >> 1) + 1, r, p, d);
  tr[o] = tr[o << 1] + tr[o << 1 | 1];
  sum[o] = sum[o << 1] + sum[o << 1 | 1];
}
inline long long Query1(long long o, long long l, long long r, long long k) {
  if (tr[o] < k) return sum[o];
  if (!k || l == r) return l * k;
  if (tr[o << 1] >= k)
    return Query1(o << 1, l, ((l + r) >> 1), k);
  else
    return Query1(o << 1 | 1, ((l + r) >> 1) + 1, r, k - tr[o << 1]) +
           sum[o << 1];
}
}  // namespace Seg
signed main() {
  scanf("%lld%lld%lld", &n, &k, &m);
  for (long long i = 1; i <= m; ++i) {
    scanf("%lld%lld%lld%lld", &l[i], &r[i], &c[i], &p[i]);
    vec.push_back(l[i]), vec.push_back(r[i] + 1);
    mx = max(mx, p[i]);
  }
  vec.push_back(1), vec.push_back(n);
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  for (long long i = 1; i <= m; ++i) {
    long long tmpl = lower_bound(vec.begin(), vec.end(), l[i]) - vec.begin(),
              tmpr =
                  lower_bound(vec.begin(), vec.end(), r[i] + 1) - vec.begin();
    op[tmpl].push_back(pair<long long, long long>(p[i], c[i]));
    op[tmpr].push_back(pair<long long, long long>(p[i], -c[i]));
  }
  long long p = vec.size();
  long long ans = 0;
  for (long long i = 0; i < p - 1; ++i) {
    for (long long j = 0; j < (long long)op[i].size(); ++j)
      Seg::Update(1, 1, mx, op[i][j].first, op[i][j].second);
    ans += Seg::Query1(1, 1, mx, k) * (vec[i + 1] - vec[i]);
  }
  printf("%lld\n", ans);
}
