#include using namespace std; template bool chmax(T &A, T B) { if (A < B) { A = B; return true; } return false; } int main() { long long N; cin >> N; vectorA(N); for (long long i = 0; i < N; i++) { cin >> A.at(i); } vector>B(N, vector(N)); for (long long i = 0; i < N; i++) { for (long long j = 0; j < N; j++) { cin >> B.at(i).at(j); } } long long ans = -1000000000; vectoranswer; for (long long i = 1; i < (1 << N); i++) { long long num = 0; vectorC; for (long long j = 0; j < N; j++) { if (i & (1 << j)) { C.push_back(j); num += A.at(j); } } for (long long j = 0; j < C.size() - 1; j++) { for (long long k = j + 1; k < C.size(); k++) { num += B.at(C.at(j)).at(C.at(k)); } } if (chmax(ans, num)) { answer = C; } } cout << ans << endl; for (long long i = 0; i < answer.size(); i++) { cout << answer.at(i) + 1; if (i != answer.size() - 1) cout << ' '; } cout << endl; }