macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( iter = $ iter : ident , $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut $ iter = s . split_whitespace ( ) ; input_inner ! { $ iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , mut $ var : usize $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , $ var : usize $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , { chars : $ base : expr } ) => { read_value ! ( $ iter , String ) . chars ( ) . map ( | c | ( c as u8 - $ base as u8 ) as usize ) . collect ::< Vec < usize >> ( ) } ; ( $ iter : expr , { char : $ base : expr } ) => { read_value ! ( $ iter , { chars : $ base } ) [ 0 ] } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , char ) => { read_value ! ( $ iter , chars ) [ 0 ] } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct CHTLine {
    slope: i64,
    intercept: i64,
}
impl CHTLine {
    pub fn new(a: i64, b: i64) -> Self {
        CHTLine {
            slope: a,
            intercept: b,
        }
    }
    pub fn value(&self, x: i64) -> i64 {
        self.slope * x + self.intercept
    }
    pub fn check(&self, l1: &Self, l2: &Self) -> bool {
        (l1.slope - self.slope) * (l2.intercept - l1.intercept)
            >= (l1.intercept - self.intercept) * (l2.slope - l1.slope)
    }
}
#[derive(Clone, Debug)]
pub struct ConvexHullTrick {
    deq: std::collections::VecDeque<CHTLine>,
}
impl ConvexHullTrick {
    pub fn new() -> Self {
        ConvexHullTrick {
            deq: std::collections::VecDeque::new(),
        }
    }
    #[doc = " k-th add_line(a_k, b_k): a_k >= a_{k+1}"]
    pub fn add_line(&mut self, a: i64, b: i64) {
        let line = CHTLine::new(a, b);
        while {
            let k = self.deq.len();
            k > 1 && self.deq[k - 2].check(&self.deq[k - 1], &line)
        } {
            self.deq.pop_back();
        }
        self.deq.push_back(line);
    }
    pub fn query(&mut self, x: i64) -> i64 {
        while {
            let k = self.deq.len();
            k > 1 && self.deq[0].value(x) >= self.deq[1].value(x)
        } {
            self.deq.pop_front();
        }
        self.deq.front().unwrap().value(x)
    }
}
fn main() {
    input! { n, c: i64, h: [i64; n] };
    let mut dp = vec![0; n];
    let mut cht = ConvexHullTrick::new();
    for i in 0..n - 1 {
        cht.add_line(-2 * h[i], dp[i] + h[i] * h[i]);
        dp[i + 1] = cht.query(h[i + 1]) + c + h[i + 1] * h[i + 1];
    }
    println!("{}", dp[n - 1]);
}


Measured memory_bytes: 15980