#include using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i) #define all(a) (a).begin(),(a).end() int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int N; cin >> N; vector A(N); rep(i, 0, N) cin >> A[i]; vector B(N, vector(N)); rep(i, 0, N) rep(j, 0, N) cin >> B[i][j]; ll ans = -(1ll << 62); int S = -1; rep(bit, 1, 1 << N) { ll res = 0; rep(i, 0, N) if ((bit >> i) & 1) res += A[i]; rep(i, 0, N - 1) rep(j, i + 1, N) if (((bit >> i) & 1) && ((bit >> j) & 1)) res += B[i][j]; if (ans < res) { ans = res; S = bit; } } cout << ans << '\n'; rep(i, 0, N) if ((S >> i) & 1) cout << i + 1 << ' '; cout << '\n'; }