#include <iostream>

using namespace std;
#define MAX 50000
int main()
{
    int A[MIN],M,i,K=0,zbir=0;
    long long int c[MIN];
    long long int d[MIN];
    long long int a;
    long long int b;
    cin >> M;
    cin >> a >> cin >> b;
    for (i=1;i<M;i++)
    cin >>c[i]>>d[i];
    for (i=1;i<=M&&b!=0;i++){
        if(c[i]==d[i]){
        A[i]=c[i];
        b-=c[i];
        zbir+=c[i];
        if(c[i]!=0)
            K++;
        }
        A[i]=min(b,d[i]);
        b-=min(b,d[i]);
        zbir+=c[i];
        if(A[i]!=0)
            k++;
    }
    cout << zbir;
    cout << K;
for(i=1;i<=0;i++){
    
    if (A[i]!=0)
        cout << "1" << i << A[i];

}
return 0;
}