#include <bits/stdc++.h>
using namespace std;
int n, h, m, i, l, r, x, a[55];
int main() {
  cin >> n >> h >> m;
  for (i = 1; i <= n; i++) a[i] = h;
  while (m--) {
    cin >> l >> r >> x;
    for (i = l; i <= r; i++)
      if (x < a[i]) a[i] = x;
  }
  m = 0;
  for (i = 1; i <= n; i++) m += a[i] * a[i];
  cout << m;
  return 0;
}
