#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

class hull_optimizer {
    struct line {
        long long m, b, value;
        double xlo;
        bool is_query, query_max;

        line(long long m, long long b, long long v, bool is_query, bool query_max)
            : m(m), b(b), value(v), xlo(-std::numeric_limits<double>::max()), is_query(is_query), query_max(query_max) {
        }

        double intersect(const line& l) const {
            if (m == l.m) {
                return std::numeric_limits<double>::max();
            }
            return (double)(l.b - b) / (m - l.m);
        }

        bool operator<(const line& l) const {
            if (l.is_query) {
                return query_max ? (xlo < l.value) : (l.value < xlo);
            }
            return m < l.m;
        }
    };

    std::set<line> hull;
    bool query_max;

    typedef std::set<line>::iterator hulliter;

    bool has_prev(hulliter it) const {
        return it != hull.begin();
    }

    bool has_next(hulliter it) const {
        return (it != hull.end()) && (++it != hull.end());
    }

    bool irrelevant(hulliter it) const {
        if (!has_prev(it) || !has_next(it)) {
            return false;
        }
        hulliter prev = it, next = it;
        --prev;
        ++next;
        return query_max ? (prev->intersect(*next) <= prev->intersect(*it))
                         : (next->intersect(*prev) <= next->intersect(*it));
    }

    hulliter update_left_border(hulliter it) {
        if ((query_max && !has_prev(it)) || (!query_max && !has_next(it))) {
            return it;
        }
        hulliter it2 = it;
        double value = it->intersect(query_max ? *--it2 : *++it2);
        line l(*it);
        l.xlo = value;
        hull.erase(it++);
        return hull.insert(it, l);
    }

   public:
    hull_optimizer(bool query_max = false)
        : query_max(query_max) {
    }

    void add_line(long long m, long long b) {
        line l(m, b, 0, false, query_max);
        hulliter it = hull.lower_bound(l);
        if (it != hull.end() && it->m == l.m) {
            if ((query_max && it->b < b) || (!query_max && b < it->b)) {
                hull.erase(it++);
            } else {
                return;
            }
        }
        it = hull.insert(it, l);
        if (irrelevant(it)) {
            hull.erase(it);
            return;
        }
        while (has_prev(it) && irrelevant(--it)) {
            hull.erase(it++);
        }
        while (has_next(it) && irrelevant(++it)) {
            hull.erase(it--);
        }
        it = update_left_border(it);
        if (has_prev(it)) {
            update_left_border(--it);
        }
        if (has_next(++it)) {
            update_left_border(++it);
        }
    }

    long long query(long long x) const {
        line q(0, 0, x, true, query_max);
        hulliter it = hull.lower_bound(q);
        if (query_max) {
            --it;
        }
        return it->m * x + it->b;
    }
};

void solve() {
    int n;
    ll C;
    cin >> n >> C;
    vector<int> h(n);
    cin >> h;
    hull_optimizer hull;
    hull.add_line(-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(h[i]);
        hull.add_line(-2LL * h[i], f + 1LL * h[i] * h[i]);
    }
    cout << f << "\n";
}

Measured memory_bytes: 16640