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 = vec![0; n]; let mut b: Vec = vec![0; n]; for i in 0..n - 1 { a[i] = itr.next().unwrap().parse().unwrap(); b[i] = itr.next().unwrap().parse().unwrap(); } let mut suma = 0; let mut sumb = 0; // // 自分以外の所に行かなくてはいけないから、自分以外の所の和 >= 自分 for i in 0..n - 1 { suma += a[i]; sumb += b[i]; } let mut amn = 1 << 30; let mut bmn = 1 << 30; for i in 0..n - 1 { // b[i] <= suma - a[i] + a_1; // が必要 // a_1 >= b[i] - (suma - a[i]) if b[i] >= suma - a[i] { amn = std::cmp::min(amn, b[i] - (suma - a[i])); } // a[i] <= sumb - b[i] + b_1; // b_1 >= a[i] - (suma - a[i]) if a[i] >= sumb - b[i] { bmn = std::cmp::min(bmn, a[i] - (sumb - b[i])); } } if bmn == 1 << 30 { bmn = 0; } if amn == 1 << 30 { amn = 0; } // ここまでで、suma == sumbにしたい && a_1 <= sumb && b_1 <= suma // amn <= a_1 <= sumb, bmn <= b_1 <= suma println!("{}", std::cmp::min(sumb - amn, suma - bmn) + 1); }