#![allow(unused_imports)] #![allow(non_snake_case)] use std::cmp::*; use std::collections::*; use std::io::Write; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn main() { let n = read::(); let mut ab = vec![]; for i in 0..n - 1 { let v = read_vec::(); ab.push((v[0], v[1])); } let a_sum = ab.iter().map(|&x| x.0).sum::(); let b_sum = ab.iter().map(|&x| x.1).sum::(); let mut count = 0; 'outer: for a_cand in 0..b_sum + 1 { let b_cand = a_cand + a_sum - b_sum; if b_cand < 0 { continue; } for i in 0..n - 1 { if ab[i].0 > (b_cand + b_sum) - ab[i].1 { continue 'outer; } } count += 1; } println!("{}", count); } fn read() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec() -> Vec { read::() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() }