#include using namespace std; const long long INF = 1000000000000000; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector A(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]; } } vector dp(1 << N, 0); for (int i = 0; i < N; i++){ dp[1 << i] += A[i]; for (int j = i + 1; j < N; j++){ dp[(1 << i) + (1 << j)] += B[i][j]; } } for (int i = 0; i < N; i++){ for (int j = 0; j < (1 << N); j++){ if (j >> i & 1){ dp[j] += dp[j - (1 << i)]; } } } int id = max_element(dp.begin(), dp.end()) - dp.begin(); cout << dp[id] << "\n"; for (int i = 0; i < N; i++){ if (id >> i & 1){ cout << i + 1 << ' '; } } cout << "\n"; }