Problem:
Score : 300 points

Problem Statement

In a public bath, there is a shower which emits water for T seconds when the switch is pushed.

If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds.
Note that it does not mean that the shower emits water for T additional seconds.

N people will push the switch while passing by the shower.
The i-th person will push the switch t_i seconds after the first person pushes it.

How long will the shower emit water in total?

Constraints

1 ≤ N ≤ 200,000

1 ≤ T ≤ 10^9

0 = t_1 < t_2 < t_3 < , ..., < t_{N-1} < t_N ≤ 10^9

T and each t_i are integers.

Input

Input is given from Standard Input in the following format:

N T
t_1 t_2 ... t_N

Output

Assume that the shower will emit water for a total of X seconds. Print X.

Sample Input 1

2 4
0 3

Sample Output 1

7

Three seconds after the first person pushes the water, the switch is pushed again and the shower emits water for four more seconds, for a total of seven seconds.

Sample Input 2

2 4
0 5

Sample Output 2

8

One second after the shower stops emission of water triggered by the first person, the switch is pushed again.

Sample Input 3

4 1000000000
0 1000 1000000 1000000000

Sample Output 3

2000000000

Sample Input 4

1 1
0

Sample Output 4

1

Sample Input 5

9 10
0 3 5 7 100 110 200 300 311

Sample Output 5

67

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

#![allow(dead_code)]
#![allow(unused_macros)]

// 入力マクロ
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// #[allow(unused_imports)]
// use std::time::Instant;
// macro_rules! measure {
//     ( $x:expr) => {{
//         let start = Instant::now();
//         let result = $x;
//         let end = start.elapsed();
//         println!("Running in : {}.{:03}s", end.as_secs(), end.subsec_millis());
//         result
//     }};
// }

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const MOD: u64 = 1_000_000_007;

fn main() {
    input! {
        n: usize, t: usize,
        a: [usize; n],
    }

    let mut ans = t;
    for (i, j) in a.windows(2).map(|x| (x[0], x[1])) {
        if j - i >= t {
            ans += t;
        } else {
            ans += j - i;
        }
    }

    println!("{}", ans);
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/// プログラムを終了
fn exit() {
    use std::process;
    process::exit(0)
}

/// 比較可能な2つの引数のうち大きい方を返す
fn max<T: PartialOrd>(n: T, m: T) -> T {
    if n >= m {
        n
    } else {
        m
    }
}

/// 比較可能な2つの引数のうち小さい方を返す
fn min<T: PartialOrd>(n: T, m: T) -> T {
    if n <= m {
        n
    } else {
        m
    }
}

/// floor + as i64
fn into_floor(a: f64) -> i64 {
    (a - a % 1.0) as i64
}

/// ceil + as i64
fn into_ceil(a: f64) -> i64 {
    (a - a % 1.0) as i64 + 1i64
}

/// "Yes", "No" を出力
fn yes_no(flag: bool) {
    if flag {
        println!("Yes");
    } else {
        println!("No");
    }
}

/// 互除法を用いて最大公約数を求める
fn gcd(n: u64, m: u64) -> u64 {
    let (mut n, mut m) = (max(n, m), min(n, m));
    if m == 0 {
        return n;
    }
    let mut _r = 0;
    while n % m != 0 {
        _r = n % m;
        n = m;
        m = _r;
    }
    m
}

/// 最小公倍数を求める
fn lcm(n: u64, m: u64) -> u64 {
    n * m / gcd(n, m)
}

/// 配列全体の最大公約数
fn gcd_vec(v: &[u64]) -> u64 {
    let mut r = v[0];
    for i in v.iter().skip(1) {
        r = gcd(r, *i);
    }
    r
}

/// 配列全体の最小公倍数
fn lcm_vec(v: &[u64]) -> u64 {
    let mut r = v[0];
    for i in v.iter().skip(1) {
        r = lcm(r, *i);
    }
    r
}

/// Find the first factor (other than 1) of a number
fn firstfac(x: u64) -> u64 {
    if x % 2 == 0 {
        return 2;
    };
    // TODO: return to step_by
    // for n in (3..).step_by(2).take_while(|m| m*m <= x) {
    for n in (1..).map(|m| 2 * m + 1).take_while(|m| m * m <= x) {
        if x % n == 0 {
            return n;
        };
    }
    // No factor found. It must be prime.
    x
}

/// Test whether a number is prime. Checks every odd number up to `sqrt(n)`.
fn is_prime(n: u64) -> bool {
    if n <= 1 {
        return false;
    }
    firstfac(n) == n
}

// TODO!
// pub fn parmutation<T: PartialOrd>(v: &Vec<T>) -> Vec<Vec<T>> {
//     let mut sorted = v;

// }