#include "bits/stdc++.h" using namespace std; using ll = long long; using P = pair; const ll INF = (1LL << 61); ll mod = 998244353; signed main() { ios::sync_with_stdio(false); cin.tie(0); ll N; cin >> N; vectorA(N); for (int i = 0; i < N; i++)cin >> A[i]; vector>B(N, vector(N)); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cin >> B[i][j]; } } ll ans = -INF; vectort; for (int bit = 0; bit < (1 << N); bit++) { ll sum = 0; vectornow; for (int i = 0; i < N; i++) { if (bit & (1 << i)) { now.push_back(i + 1); sum += A[i]; } } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { sum += B[i][j]; } } if (ans < sum) { ans = sum; t = now; } } cout << ans << endl; for (int i = 0; i < t.size(); i++) { cout << t[i]; if (i == t.size() - 1)cout << endl; else cout << " "; } return 0; }