#include <bits/stdc++.h>
using namespace std;
int x4[] = {0, 0, 1, -1};
int y4[] = {1, -1, 0, 0};
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  int n, h, m;
  int a, b, x;
  cin >> n >> h >> m;
  vector<int> ara(n, 1 << 30);
  for (int i = 0; i < m; ++i) {
    cin >> a >> b >> x;
    for (int j = a - 1; j < b; ++j) {
      ara[j] = min(ara[j], x);
    }
  }
  for (int i = 0; i < n; ++i) {
    if (ara[i] == 1 << 30) {
      ara[i] = h;
    }
  }
  int sum = accumulate(ara.begin(), ara.end(), 0,
                       [](int a, int i) { return a + ((i) * (i)); });
  cout << sum << "\n";
  return 0;
}
