//include //------------------------------------------ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";} #define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}} using LL = long long; //------------------------------------------ //------------------------------------------ int main() { int N; cin >> N; vector A(N - 1), B(N - 1); for (int i = 0; i < N - 1; i++) cin >> A[i] >> B[i]; LL sumA = accumulate(A.begin(), A.end(), 0LL); LL sumB = accumulate(B.begin(), B.end(), 0LL); LL ans = 0; for (LL a = 0; a <= sumB; a++) { LL b = (sumA + a) - sumB; if (b < 0) continue; if (b > sumA) continue; bool good = true; for (int i = 0; i < N; i++) { if (B[i] > a + sumA - A[i]) { good = false; } } if(good) ans++; } cout << ans << endl; return 0; }