#include <bits/stdc++.h>
using namespace std;
struct greateri {
  template <class T>
  bool operator()(T const &a, T const &b) const {
    return a > b;
  }
};
int houses[51];
int main() {
  int m, n, z;
  cin >> z >> n >> m;
  for (int i = 0; i < z; ++i) {
    houses[i] = n;
  }
  for (int i = 0; i < m; ++i) {
    int l, r, val;
    cin >> l >> r >> val;
    for (int i = l - 1; i <= r - 1; ++i) {
      houses[i] = min(houses[i], val);
    }
  }
  int ans = 0;
  for (int i = 0; i < z; ++i) {
    ans += (houses[i] * houses[i]);
  }
  cout << ans;
  return 0;
}
