#include #include #include using namespace std; int main(int argc, char* argv[]) { int n; cin>>n; vector A1(n); int i,j,k; for (i=1;i>A1[i]; } vector B(n+1),C(n+1),D(n+1); for (i=1;i<=n;i++){ cin>>B[i]>>C[i]; } int aw=0; j=1; for (i=2;i<=n;i++){ while (j=B[i]){ aw+=a*B[i]; C[j]-=B[i]; B[i]=0; }else{ aw+=a*C[j]; B[i]-=C[j]; C[j]=0; j++; i--; } } cout<