#pragma region

#ifdef LOCAL
#define debug cout
#else
#define debug \
    if (0) cout
#endif

#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
using ll = long long;

template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[ ";
    for (auto e : v) os << e << " ";
    return os << "]";
}

template <typename T, typename V>
ostream& operator<<(ostream& os, set<T, V> v) {
    os << "{ ";
    for (auto e : v) os << e << " ";
    return os << "}";
}

template <typename T, typename V, typename S>
ostream& operator<<(ostream& os, map<T, V, S> v) {
    os << "{ ";
    for (auto e : v) os << e << " ";
    return os << "}";
}

template <typename T, typename V>
ostream& operator<<(ostream& os, pair<T, V> x) {
    return os << "( " << x.first << ", " << x.second << " )";
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& e : v) is >> e;
    return is;
}

template <typename T, typename V>
istream& operator>>(istream& is, pair<T, V>& x) {
    return is >> x.first >> x.second;
}

void solve();

int main() {
#ifdef LOCAL
    freopen("data.txt", "r", stdin);
#else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    solve();
}

#pragma endregion

using pll = pair<ll, ll>;

// Query for minimum
// Decreasing slope additions
// General queries
struct convex_hull {
    deque<pll> lines;

    // Only requires that l1.first <= l2.first <= l3.first
    bool bad(pll l1, pll l2, pll l3) {
        return (l2.second - l3.second) * (l2.first - l1.first) >= (l1.second - l2.second) * (l3.first - l2.first);
    }

    // Add y=mx+b. Decreasing slope!
    void add_min_slope(ll m, ll b) {
        if (!lines.empty()) {
            assert(m <= lines.front().first);
        }
        pll cur = {m, b};
        while (lines.size() >= 2 && bad(cur, lines[0], lines[1])) {
            lines.pop_front();
        }
        lines.push_front(cur);
    }

    void add_max_slope(ll m, ll b) {
        if (!lines.empty()) {
            assert(m >= lines.back().first);
        }
        pll cur = {m, b};
        while (lines.size() >= 2 && bad(lines[lines.size() - 2], lines[lines.size() - 1], cur)) {
            lines.pop_back();
        }
        lines.push_back(cur);
    }

    ll query_min(ll x) {
        int lo = 0, hi = lines.size() - 1;
        while (lo < hi) {
            int mid = hi - (hi - lo) / 2;
            auto l2 = lines[mid], l1 = lines[mid - 1];
            if (l1.second - l2.second >= x * (l2.first - l1.first)) {
                lo = mid;
            } else {
                hi = mid - 1;
            }
        }
        return lines[lo].first * x + lines[lo].second;
    }
};

void solve() {
    int n;
    ll C;
    cin >> n >> C;
    vector<int> h(n);
    cin >> h;
    convex_hull hull;
    hull.add_max_slope(-2LL * h[n - 1], 1LL * h[n - 1] * h[n - 1]);
    ll f;
    for (int i = n - 2; i >= 0; --i) {
        f = 1LL * h[i] * h[i] + C + hull.query_min(h[i]);
        hull.add_max_slope(-2LL * h[i], 1LL * h[i] * h[i] + 1LL * f);
    }
    // hull.add_min_slope(-2LL * h[0], 1LL * h[0] * h[0]);
    // ll f;
    // for (int i = 1; i < n; ++i) {
    //     f = 1LL * h[i] * h[i] + C + hull.query_min(h[i]);
    //     hull.add_min_slope(-2LL * h[i], f + 1LL * h[i] * h[i]);
    // }
    cout << f << "\n";
}

Measured memory_bytes: 4352