#include <bits/stdc++.h>
using namespace std;
;
const int BufferSize = 1 << 16;
char buffer[BufferSize], *head, *tail;
inline char Getchar() {
  if (head == tail) {
    int l = fread(buffer, 1, BufferSize, stdin);
    tail = (head = buffer) + l;
  }
  return *head++;
}
inline int read() {
  int x = 0, f = 1;
  char c = Getchar();
  for (; !isdigit(c); c = Getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = Getchar()) x = x * 10 + c - '0';
  return x * f;
}
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 3e5 + 5;
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3f;
int a[maxn];
int main() {
  int n, h, m;
  scanf("%d%d%d", &n, &h, &m);
  for (int i = 1; i <= n; i++) {
    a[i] = h;
  }
  int l, r, maxx;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &l, &r, &maxx);
    for (int j = l; j <= r; j++) {
      a[j] = min(a[j], maxx);
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += a[i] * a[i];
  }
  printf("%lld\n", ans);
  return 0;
}
