#include <bits/stdc++.h>
using namespace std;
int n, m, h;
int a[500];
int x, y, z;
long long sum;
bool cmp(int a, int b) { return a > b; }
int main() {
  memset(a, 0x3f, sizeof(a));
  scanf("%d%d%d", &n, &h, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    for (int j = x; j <= y; j++) a[j] = min(a[j], z);
  }
  sort(a + 1, a + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    if (a[i] > h) a[i] = h;
    sum += a[i] * a[i];
  }
  printf("%lld", sum);
}
