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