#include#include #include #include #include using namespace std;#define ll long long#define P pair ll a[40];P p[1 << 20];ll Abs(ll x) { if (x >= 0) return x; return -x;}int main() { int n; while (scanf("%d", &n) != EOF && n) { for (int i = 0; i < n; i++) scanf("%lld", &a[i]); int rn = n / 2; P res; res = {Abs(a[0]), 1}; for (int i = 1; i < 1 << rn; i++) { p[i] = { 0, 0}; for (int j = 0; j < rn; j++) { if (i >> j & 1) { p[i].first += a[j]; p[i].second++; } } //只在p[]中取数 res = min(res, P(Abs(p[i].first), p[i].second)); } sort(p + 1, p + (1 << rn)); //去重 int m = 2; for (int i = 2; i < 1 << rn; i++) { if (p[m - 1].first < p[i].first) p[m++] = p[i]; } for (int i = 1; i < 1 << (n - rn); i++) { ll tmp = 0; int tnum = 0; for (int j = 0; j < n - rn; j++) { if (i >> j & 1) { tmp += a[j + rn]; tnum++; } } //不在p[]取数 res = min(res, P(Abs(tmp), tnum)); int pos = lower_bound(p + 1, p + m, P(-tmp, 0)) - p; for (int j = -1; j <= 0; j++) { if (j + pos < 1 || j + pos >= m) continue; res = min(res, P(Abs(tmp + p[pos + j].first), tnum + p[pos + j].second)); } } printf("%lld %d\n", res.first, res.second); }}