#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m, h;
  cin >> n >> h >> m;
  long long arr[n];
  for (long long i = 0; i < n; i++) arr[i] = h;
  for (long long i = 0; i < m; i++) {
    long long l, r, x;
    cin >> l >> r >> x;
    for (long long j = l - 1; j < r; j++) arr[j] = min(arr[j], x);
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    ans += arr[i] * arr[i];
  }
  cout << ans;
  return 0;
}
