#include <bits/stdc++.h>
using namespace std;
int poww(int x) { return x * x; }
int ssum = 0, n, m, maxh, f[60];
struct node {
  int left, right, limit;
} a[60];
int main() {
  scanf("%d%d%d", &n, &maxh, &m);
  for (int i = 1; i <= m; i++)
    scanf("%d%d%d", &a[i].left, &a[i].right, &a[i].limit);
  for (int i = 1; i <= n; i++) f[i] = maxh;
  for (int i = 1; i <= m; i++)
    for (int j = a[i].left; j <= a[i].right; j++)
      f[j] = f[j] < a[i].limit ? f[j] : a[i].limit;
  for (int i = 1; i <= n; i++) ssum += (poww(f[i]));
  printf("%d", ssum);
  return 0;
}
