#include <bits/stdc++.h>
int main(int argc, char const *argv[]) {
  int n, h, m, l, r, x, ans = 0;
  scanf("%d %d %d", &n, &h, &m);
  int arr[n];
  for (int i = 0; i < n; ++i) {
    arr[i] = h;
  }
  for (int i = 0; i < m; ++i) {
    scanf("%d %d %d", &l, &r, &x);
    for (int i = l - 1; i < r; ++i) {
      if (arr[i] > x) {
        arr[i] = x;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    ans = ans + pow(arr[i], 2);
  }
  printf("%d\n", ans);
  return 0;
}
