#include using namespace std; #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = (n)-1; i >= 0; --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template void chmax(T& a, const T& b) {a = max(a, b);} template void chmin(T& a, const T& b) {a = min(a, b);} using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; VL a(n); rep(i, n) cin >> a[i]; VVL b(n, VL(n)); rep(i, n) rep(j, n) cin >> b[i][j]; ll mx = -1, mxv = -1; rep(s, 1 << n) { ll t = 0; rep(i, n) if (s >> i & 1) t += a[i]; rep(i, n) rep(j, i) if (s >> i & s >> j & 1) t += b[i][j]; if (t > mx) { mx = t; mxv = s; } } cout << mx << '\n'; VI ans; rep(i, n) if (mxv >> i & 1) ans.push_back(i + 1); int sz = ans.size(); rep(i, sz) cout << ans[i] << " \n"[i + 1 == sz]; }