#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; ll A[20]; ll B[20][20]; int main() { int N; cin >> N; for (int i = 0; i < N; ++i) { cin >> A[i]; } for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { cin >> B[i][j]; } } ll ans = -1; int best = 0; for (int mask = 0; mask < (1 << N); ++mask) { ll v = 0; for (int i = 0; i < N; ++i) { if ((mask >> i & 1) == 0) continue; v += A[i]; } for (int i = 0; i < N; ++i) { if ((mask >> i & 1) == 0) continue; for (int j = i + 1; j < N; ++j) { if ((mask >> j & 1) == 0) continue; v += B[i][j]; } } if (ans < v) { ans = v; best = mask; } } cout << ans << endl; for (int i = 0; i < N; ++i) { if ((best >> i & 1) == 0) continue; cout << i + 1 << " "; } cout << endl; return 0; }