#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, h, m;
  scanf("%d%d%d", &n, &h, &m);
  vector<int> range;
  range.resize(n + 1);
  fill(range.begin(), range.end(), h);
  for (int i = 0; i < m; i++) {
    int l, r, x;
    scanf("%d%d%d", &l, &r, &x);
    for (int j = l; j <= r; j++) {
      if (range[j] > x) range[j] = x;
    }
  }
  int profit = 0;
  for (int i = 1; i <= n; i++) {
    profit += range[i] * range[i];
  }
  printf("%d", profit);
}
