#![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; for a_cand in 0..b_sum + 1 { let b_cand = a_cand + a_sum - b_sum; if b_cand < 0 { continue; } /* if b_cand < a_sum - b_sum { continue; } if a_cand < b_sum - a_sum { continue; } */ 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() }