use proconio::{input, marker::Usize1}; fn main() { input! { n:usize, s:Usize1, t:Usize1, a:[usize;n], } let ans = if n % 2 != 0 { let mut point = [0, 0]; for i in 0..n { match f(s, t, i, n) { 0 | 2 => point[0] += a[i], _ => point[1] += a[i], } // println!("{:?}",point); } point[0] as i64 - point[1] as i64 } else { let mut point = [0, 0]; let mut tmp = vec![]; for i in 0..n { match f(s, t, i, n) { 0 => point[0] += a[i], 1 => point[1] += a[i], _ => tmp.push(a[i]), } // println!("{:?}",point); } let (add_s, add_t) = if tmp.is_empty() { (0, 0) } else { (tmp[0].max(tmp[1]), tmp[0].min(tmp[1])) }; (point[0] + add_s) as i64 - (point[1] + add_t) as i64 }; println!("{}", ans); } fn f(s: usize, t: usize, p: usize, n: usize) -> usize { let d_s = if s < p { (p - s).min(s + n - p) } else { (s - p).min(p + n - s) }; let d_t = if t < p { (p - t).min(t + n - p) } else { (t - p).min(p + n - t) }; if d_s < d_t { 0 } else if d_t < d_s { 1 } else { 2 } }