#include <bits/stdc++.h>
using namespace std;
int const N = 51;
int n, m, h, l[N], r[N], x[N], cm[N];
int main() {
  scanf("%d%d%d", &n, &h, &m);
  long long an = 0;
  for (int i = 1; i <= n; ++i) cm[i] = h;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", &l[i], &r[i], &x[i]);
    for (int j = l[i]; j <= r[i]; ++j) {
      cm[j] = min(cm[j], x[i]);
    }
  }
  for (int i = 1; i <= n; ++i) {
    an += (cm[i] * cm[i]);
  }
  printf("%lld\n", an);
}
