#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { int32_t n; cin >> n; vector as(n); for (auto &&a : as) { cin >> a; } vector> bmat(n, vector(n)); for (auto &&bs : bmat) { for (auto &&b : bs) { cin >> b; } } int64_t ans = -1, pat = 0; for (auto st = 0; st < (1 << n); ++st) { int64_t s = 0; for (auto i = 0; i < n; ++i) { if (!((st >> i) & 0b1)) continue; for (auto j = 0; j < n; ++j) { if (!((st >> j) & 0b1)) continue; s += bmat[i][j]; } } s /= 2; for (auto i = 0; i < n; ++i) { if ((st >> i) & 0b1) s += as[i]; } if (s > ans) { ans = s; pat = st; } } cout << ans << endl; bool first = true; for (auto i = 0; i < n; ++i) { if (!((pat >> i) & 0b1)) continue; cout << (first ? "" : " ") << i + 1; first = false; } cout << endl; return 0; }