#include #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)n;++i) #define each(a, b) for(auto (a): (b)) #define all(v) (v).begin(),(v).end() #define fi first #define se second #define pb push_back #define show(x) cout <<#x<<" = "<<(x)<P; const int MAX_N = 101; const int MAX_W = 100002; int dp[MAX_N][MAX_W]; int main() { int n; cin >> n; vector v(n),w(n); rep(i,n){ cin >> v[i] >> w[i]; } rep(i,n){ rep(j,MAX_W-1){ if(j - w[i] >= 0){ dp[i+1][j] = max(dp[i+1][j],dp[i][j-w[i]] + v[i]); } dp[i+1][j] = max(dp[i+1][j],dp[i][j]); } } int mn = INF; int mx = -1; int V; cin >> V; rep(i,MAX_W-1){ if(dp[n][i] == V){ mn = min(mn,i); mx = max(mx,i); } } if(mx == MAX_W-2){ cout << max(mn,1) << endl; cout << "inf\n"; }else{ cout << max(mn,1) << endl; cout << mx << endl; } return 0; }