use std::io::*; fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let mut a: Vec = (0..n) .map(|_| itr.next().unwrap().parse().unwrap()) .collect(); let sum = a.iter().fold(0, |acc, x| acc + x); let mut height = 1; while height * (height + 1) + height + 1 <= sum { height += 1; } let hidx = height - 1; a.resize(hidx * 2 + 1, 0); let excess = sum - height * (height - 1) - height; let mut need = 0; if a[hidx] < height { need = height - a[hidx]; } for i in 0..hidx { if i < hidx * 2 + 1 && a[i] < i + 1 { need += i + 1 - a[i]; } if hidx * 2 - i < hidx * 2 + 1 && a[hidx * 2 - i] < i + 1 { need += i + 1 - a[hidx * 2 - i]; } } println!("{}", excess + need); }