#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
int IT_MAX = 1 << 19;
const long long MOD = 998244353;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
long long n, h, m, l, r, x, ans = 0;
long long a[10000];
int main() {
  cin >> n >> h >> m;
  for (int i = 0; i < (n); i++) a[i + 1] = h;
  for (int i = 0; i < m; i++) {
    cin >> l >> r >> x;
    for (int j = l; j <= r; j++) {
      a[j] = min(a[j], x);
    }
  }
  for (int i = 0; i < (n); i++) ans = ans + a[i + 1] * a[i + 1];
  cout << ans;
  return 0;
}
