Problem: You are planning to build housing on a street. There are n spots available on the street on which you can build a house. The spots are labeled from 1 to n from left to right. In each spot, you can build a house with an integer height between 0 and h.

In each spot, if a house has height a, you will gain a^2 dollars from it.

The city has m zoning restrictions. The i-th restriction says that the tallest house from spots l_i to r_i (inclusive) must be at most x_i.

You would like to build houses to maximize your profit. Determine the maximum profit possible.

Input

The first line contains three integers n, h, and m (1 ≤ n,h,m ≤ 50) — the number of spots, the maximum height, and the number of restrictions.

Each of the next m lines contains three integers l_i, r_i, and x_i (1 ≤ l_i ≤ r_i ≤ n, 0 ≤ x_i ≤ h) — left and right limits (inclusive) of the i-th restriction and the maximum possible height in that range.

Output

Print a single integer, the maximum profit you can make.

Examples

Input


3 3 3
1 1 1
2 2 3
3 3 2


Output


14


Input


4 10 2
2 3 8
3 4 7


Output


262

Note

In the first example, there are 3 houses, the maximum height of a house is 3, and there are 3 restrictions. The first restriction says the tallest house between 1 and 1 must be at most 1. The second restriction says the tallest house between 2 and 2 must be at most 3. The third restriction says the tallest house between 3 and 3 must be at most 2.

In this case, it is optimal to build houses with heights [1, 3, 2]. This fits within all the restrictions. The total profit in this case is 1^2 + 3^2 + 2^2 = 14.

In the second example, there are 4 houses, the maximum height of a house is 10, and there are 2 restrictions. The first restriction says the tallest house from 2 to 3 must be at most 8. The second restriction says the tallest house from 3 to 4 must be at most 7.

In this case, it's optimal to build houses with heights [10, 8, 7, 7]. We get a profit of 10^2+8^2+7^2+7^2 = 262. Note that there are two restrictions on house 3 and both of them must be satisfied. Also, note that even though there isn't any explicit restrictions on house 1, we must still limit its height to be at most 10 (h=10).

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& i : v) is >> i;
  return is;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (auto& i : v) os << i << ' ';
  return os;
}
template <typename T, typename U>
istream& operator>>(istream& is, pair<T, U>& p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& p) {
  os << p.first << ' ' << p.second;
  return os;
}
template <typename T, typename U>
pair<T, U> operator-(pair<T, U> a, pair<T, U> b) {
  return make_pair(a.first - b.first, a.second - b.second);
}
template <typename T, typename U>
pair<T, U> operator+(pair<T, U> a, pair<T, U> b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
struct dinic_edge {
  int from, to;
  long long mx;
};
long long max_flow_dinic(vector<vector<pair<int, long long>>> g_main, int s,
                         int t) {
  int n = g_main.size();
  vector<vector<int>> g(n);
  vector<dinic_edge> e;
  for (int u = 0; u < n; ++u) {
    for (auto pr : g_main[u]) {
      int v = pr.first;
      long long w = pr.second;
      g[u].push_back(e.size());
      e.push_back({u, v, w});
      g[v].push_back(e.size());
      e.push_back({v, u, 0});
    }
  }
  long long flow = 0;
  vector<int> layer(n, -5);
  vector<int> q(n + 10);
  int ql, qr;
  vector<int> ptr(n, 0);
  for (int i = 0; i < n; ++i) {
    layer.assign(n, -5);
    ptr.assign(n, 0);
    ql = 0;
    qr = 1;
    q[0] = s;
    layer[s] = 0;
    while (ql < qr) {
      int v = q[ql++];
      for (auto k : g[v]) {
        if (e[k].mx > 0 && layer[e[k].to] == -5) {
          layer[e[k].to] = layer[v] + 1;
          q[qr++] = e[k].to;
        }
      }
    }
    if (layer[t] == -5) break;
    long long prev_flow = flow;
    while (true) {
      function<long long(int, long long)> go = [&](int v,
                                                   long long now) -> long long {
        if (v == t) return now;
        while (ptr[v] < g[v].size()) {
          if (layer[v] + 1 == layer[e[g[v][ptr[v]]].to] &&
              e[g[v][ptr[v]]].mx > 0) {
            long long next = min(now, e[g[v][ptr[v]]].mx);
            long long x = go(e[g[v][ptr[v]]].to, next);
            if (x > 0) {
              e[g[v][ptr[v]]].mx -= x;
              e[g[v][ptr[v]] ^ 1].mx += x;
              return x;
            } else {
              ++ptr[v];
            }
          } else {
            ++ptr[v];
          }
        }
        return 0;
      };
      long long el_flow = go(s, 1e9l * 1e9l * 4l);
      if (el_flow == 0) break;
      flow += el_flow;
    }
    if (flow == prev_flow) break;
  }
  return flow;
}
const long long inf = 1e7;
int main() {
  int n, h, m;
  cin >> n >> h >> m;
  vector<vector<pair<int, long long>>> g(2 + n * (h + 2) + m);
  int k = g.size();
  for (int j = 0; j < n; ++j) {
    for (int i = 1; i <= h + 1; ++i) {
      g[j * (h + 2) + i + 2].emplace_back(j * (h + 2) + i - 1 + 2, inf);
      g[j * (h + 2) + i - 1 + 2].emplace_back(j * (h + 2) + i + 2,
                                              h * h - (i - 1) * (i - 1));
    }
    g[0].emplace_back(j * (h + 2) + 2, inf);
    g[j * (h + 2) + (h + 1) + 2].emplace_back(1, inf);
  }
  for (int i = 0; i < m; ++i) {
    int l, r, x, c;
    cin >> l >> r >> x >> c;
    --l;
    --r;
    ++x;
    for (int j = l; j <= r; ++j) {
      g[j * (h + 2) + x + 2].emplace_back(k - m + i, inf);
    }
    g[k - m + i].emplace_back(1, c);
  }
  cout << n * h * h - max_flow_dinic(g, 0, 1) << '\n';
  return 0;
}