use std::cmp; fn main() { let n: usize = { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); buf.trim_end().parse().unwrap() }; let (s, t): (usize, usize) = { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); let mut iter = buf.split_whitespace(); ( iter.next().unwrap().parse::().unwrap() - 1, iter.next().unwrap().parse::().unwrap() - 1, ) }; let a: Vec = { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); let iter = buf.split_whitespace(); iter.map(|x| x.parse().unwrap()).collect() }; let (mut l0, mut l1) = (s, t); let (mut r0, mut r1) = (s, t); let (mut c0, mut c1) = (a[s], a[t]); for i in 0..(n - 2) { if i % 2 == 0 { let d0 = cmp::max(l0, r1) - cmp::min(l0, r1); let x0 = (r1 + (d0 + 1) / 2) % n; let d1 = cmp::max(l1, r0) - cmp::min(l1, r0); let x1 = (l1 + (d1 + 1) / 2) % n; if d1 == 1 || d0 != 1 && a[x0] > a[x1] { l0 = (l0 + n - 1) % n; c0 += a[x0]; } else { r0 = (r0 + 1) % n; c0 += a[x1]; } } else { let d0 = cmp::max(l0, r1) - cmp::min(l0, r1); let x0 = (l0 + (d0 + 1) / 2) % n; let d1 = cmp::max(l1, r0) - cmp::min(l1, r0); let x1 = (r0 + (d1 + 1) / 2) % n; if d1 == 1 || d0 != 1 && a[x0] > a[x1] { r1 = (r1 + 1) % n; c1 += a[x0]; } else { l1 = (l1 + n - 1) % n; c1 += a[x1]; } } } println!("{}", c0 as isize - c1 as isize); }