#define _USE_MATH_DEFINES #include using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; long long ans = -(1LL << 60); vector a(n); for (auto& x : a) cin >> x; vector> b(n, vector(n)); for (auto& v : b) for (auto& x : v) cin >> x; vector ans_sounds; for (int mask = 0; mask < (1 << n); mask++) { long long cur = 0; for (int i = 0; i < n; i++) if ((mask >> i) & 1) cur += a[i]; long long bonus = 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { if ((mask >> i) & 1 && (mask >> j) & 1) bonus += b[i][j]; } bonus >>= 1; cur += bonus; if (cur > ans) { ans = cur; ans_sounds.clear(); for (int i = 0; i < n; i++) if ((mask >> i) & 1) ans_sounds.emplace_back(i + 1); } } cout << ans << endl; for (int i = 0; i < (int) ans_sounds.size(); i++) { if (i > 0) cout << " "; cout << ans_sounds[i]; } cout << endl; return 0; }