#include <bits/stdc++.h>
using namespace std;
#define task "DOMINO"
#define ll long long int
#define pb push_back
#define el "\n"
#define vll vector<long long>
const ll N = 1e3 + 2;
ll n, a[10000], b[10000], dp[N][N], s = 0, ans = 1e9, res = 1e9;
//code cua HoaRoiCuaPhatVanVatCuiDau
void tassk(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen(task".inp","r"))
{
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
}
void solve() {
cin >> n;
for (int i = 1; i <= n; i++){
cin >> a[i] >> b[i];
s += a[i] + b[i];
}
for (int i = 0; i <= n; i++){
for (int j = 0; j <= s; j++){
dp[i][j] = 1e9;
}
}
dp[0][0] = 0;
for (int i = 1; i <= n; i++){
for (int j = s; j >= a[i]; j--) dp[i][j] = min(dp[i][j], dp[i - 1][j - a[i]]);
for (int j = s; j >= b[i]; j--) dp[i][j] = min(dp[i][j], dp[i - 1][j - b[i]] + 1);
}
for (ll i = 0; i <= s; i++){
if (dp[n][i] < 1e9){
if (ans > abs(s - i * 2)){
ans = abs(s - i * 2);
res = dp[n][i];
}
else if (ans == abs(s - i * 2)) res = min(dp[n][i], res);
}
}
cout << ans << " " << res << el;
}
int main()
{
tassk();
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgdGFzayAiRE9NSU5PIgojZGVmaW5lIGxsIGxvbmcgbG9uZyBpbnQKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBlbCAiXG4iCiNkZWZpbmUgdmxsIHZlY3Rvcjxsb25nIGxvbmc+CmNvbnN0IGxsIE4gPSAxZTMgKyAyOwpsbCBuLCBhWzEwMDAwXSwgYlsxMDAwMF0sIGRwW05dW05dLCBzID0gMCwgYW5zID0gMWU5LCByZXMgPSAxZTk7Ci8vY29kZSBjdWEgSG9hUm9pQ3VhUGhhdFZhblZhdEN1aURhdQp2b2lkIHRhc3NrKCl7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOwogICAgY2luLnRpZSgwKTsKICAgIGNvdXQudGllKDApOwogICAgaWYgKGZvcGVuKHRhc2siLmlucCIsInIiKSkKICAgIHsKICAgICAgICBmcmVvcGVuKHRhc2siLmlucCIsInIiLHN0ZGluKTsKICAgICAgICBmcmVvcGVuKHRhc2siLm91dCIsInciLHN0ZG91dCk7CiAgICB9Cn0Kdm9pZCBzb2x2ZSgpIHsKICAgIGNpbiA+PiBuOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKXsKICAgICAgICBjaW4gPj4gYVtpXSA+PiBiW2ldOwogICAgICAgIHMgKz0gYVtpXSArIGJbaV07CiAgICB9CiAgICBmb3IgKGludCBpID0gMDsgaSA8PSBuOyBpKyspewogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDw9IHM7IGorKyl7CiAgICAgICAgICAgIGRwW2ldW2pdID0gMWU5OwogICAgICAgIH0KICAgIH0KICAgIGRwWzBdWzBdID0gMDsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkrKyl7CiAgICAgICAgZm9yIChpbnQgaiA9IHM7IGogPj0gYVtpXTsgai0tKSBkcFtpXVtqXSA9IG1pbihkcFtpXVtqXSwgZHBbaSAtIDFdW2ogLSBhW2ldXSk7CiAgICAgICAgZm9yIChpbnQgaiA9IHM7IGogPj0gYltpXTsgai0tKSBkcFtpXVtqXSA9IG1pbihkcFtpXVtqXSwgZHBbaSAtIDFdW2ogLSBiW2ldXSArIDEpOwogICAgfQogICAgZm9yIChsbCBpID0gMDsgaSA8PSBzOyBpKyspewogICAgICAgIGlmIChkcFtuXVtpXSA8IDFlOSl7CiAgICAgICAgICAgIGlmIChhbnMgPiBhYnMocyAtIGkgKiAyKSl7CiAgICAgICAgICAgICAgICBhbnMgPSBhYnMocyAtIGkgKiAyKTsKICAgICAgICAgICAgICAgIHJlcyA9IGRwW25dW2ldOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UgaWYgKGFucyA9PSBhYnMocyAtIGkgKiAyKSkgcmVzID0gbWluKGRwW25dW2ldLCByZXMpOwogICAgICAgIH0KICAgIH0KICAgIGNvdXQgPDwgYW5zIDw8ICIgIiA8PCByZXMgPDwgZWw7Cn0KaW50IG1haW4oKQp7CiAgICB0YXNzaygpOwogICAgc29sdmUoKTsKICAgIHJldHVybiAwOwp9Cg==