Problem:
Score : 100 points

Problem Statement

There are N stones, numbered 1, 2, \ldots, N.
For each i (1 \leq i \leq N), the height of Stone i is h_i.
Here, h_1 < h_2 < \cdots < h_N holds.

There is a frog who is initially on Stone 1.
He will repeat the following action some number of times to reach Stone N:

If the frog is currently on Stone i, jump to one of the following: Stone i + 1, i + 2, \ldots, N. Here, a cost of (h_j - h_i)^2 + C is incurred, where j is the stone to land on.

Find the minimum possible total cost incurred before the frog reaches Stone N.

Constraints

All values in input are integers.

2 \leq N \leq 2 \times 10^5

1 \leq C \leq 10^{12}

1 \leq h_1 < h_2 < \cdots < h_N \leq 10^6

Input

Input is given from Standard Input in the following format:

N C
h_1 h_2 \ldots h_N

Output

Print the minimum possible total cost incurred.

Sample Input 1

5 6
1 2 3 4 5

Sample Output 1

20

If we follow the path 1 → 3 → 5, the total cost incurred would be ((3 - 1)^2 + 6) + ((5 - 3)^2 + 6) = 20.

Sample Input 2

2 1000000000000
500000 1000000

Sample Output 2

1250000000000

The answer may not fit into a 32-bit integer type.

Sample Input 3

8 5
1 3 4 5 10 11 12 13

Sample Output 3

62

If we follow the path 1 → 2 → 4 → 5 → 8, the total cost incurred would be ((3 - 1)^2 + 5) + ((5 - 3)^2 + 5) + ((10 - 5)^2 + 5) + ((13 - 10)^2 + 5) = 62.

Solution in Rust (1.15.1) (judge verdict: Accepted)

mod lichao {
    use std;
    type T = i64;
    const INF: T = std::i64::MAX;
    fn get_mid(l: T, r: T) -> T {
        (l + r) / 2
    }
    #[derive(Clone, Copy)]
    pub struct Line(T, T);
    impl Line {
        fn eval(&self, x: T) -> T {
            self.0 * x + self.1
        }
    }
    type Link = Option<Box<Node>>;
    struct Node {
        line: Line,
        left: Link,
        right: Link,
    }
    impl Node {
        fn find(node: &Link, left: T, right: T, x: T) -> T {
            let mut node = node;
            let mut ans = INF;
            let mut l = left;
            let mut r = right;
            while let Some(t) = node.as_ref() {
                let val = t.line.eval(x);
                if val < ans {
                    ans = val;
                }
                let m = get_mid(l, r);
                node = if x < m {
                    r = m;
                    &t.left
                } else {
                    l = m;
                    &t.right
                };
            }
            ans
        }
        fn insert(node: &mut Link, l: T, r: T, mut line: Line) {
            if node.is_none() {
                *node = Some(Box::new(Node {
                    line: line,
                    left: None,
                    right: None,
                }));
                return;
            }
            let node = node.as_mut().unwrap();
            if node.line.eval(l) > line.eval(l) {
                std::mem::swap(&mut node.line, &mut line);
            }
            let m = get_mid(l, r);
            if node.line.eval(r) < line.eval(r) {
                return;
            } else if node.line.eval(m) < line.eval(m) {
                Node::insert(&mut node.right, m, r, line);
            } else {
                std::mem::swap(&mut node.line, &mut line);
                Node::insert(&mut node.left, l, m, line);
            }
        }
    }
    pub struct LiChaoTree {
        root: Link,
        left: T,
        right: T,
    }
    impl LiChaoTree {
        pub fn new(left: T, right: T) -> Self {
            LiChaoTree {
                root: None,
                left: left,
                right: right,
            }
        }
        pub fn insert(&mut self, a: T, b: T) {
            Node::insert(&mut self.root, self.left, self.right, Line(a, b));
        }
        pub fn find(&self, x: T) -> T {
            assert!(self.left <= x && x < self.right);
            Node::find(&self.root, self.left, self.right, x)
        }
    }
}

use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let c: i64 = it.next().unwrap().parse().unwrap();
    let h: Vec<i64> = it.map(|s| s.parse().unwrap()).collect();
    let mut cht = lichao::LiChaoTree::new(1, 1_000_000 + 1);
    cht.insert(-2 * h[0], c + h[0] * h[0]);
    for &h in h[1..(n - 1)].iter() {
        let v = cht.find(h) + h * h;
        cht.insert(-2 * h, v + c + h * h);
    }
    let ans = cht.find(h[n - 1]) + h[n - 1] * h[n - 1];
    println!("{}", ans);
}

fn main() {
    run();
}