#include using namespace std; #define modulo 998244353 #define mod(mod_x) ((((long long)mod_x+modulo))%modulo) #define Inf 1000000000000000000 int main(){ int N; cin>>N; int sumA=0,sumB=0; vector A(N-1),B(N-1); for(int i=0;i>A[i]>>B[i]; sumA += A[i]; sumB += B[i]; } int AA,BB; if(A>B){ AA=0; BB=sumA-sumB; sumB+=BB; } else{ AA=sumB-sumA; BB=0; sumA+=AA; } int ans = 0; while(true){ bool f = true; for(int i=0;isumB-B[i]||B[i]>sumA-A[i]){ AA++; BB++; sumA++; sumB++; f=false; break; } } if(!f)continue; if(AA>sumB-BB||BB>sumA-AA){ break; } ans++; AA++; BB++; sumA++; sumB++; } cout<