#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, h, m, ans = 0, l, r, x;
  cin >> n >> h >> m;
  int 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 j = l; j <= r; j++) {
      if (a[j] > x) {
        a[j] = x;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    ans = ans + a[i] * a[i];
  }
  cout << ans << endl;
}
