#include using namespace std; struct uns_t {} uns; template auto vec(Element init, Head arg, Args ...args) { if constexpr (sizeof...(Args) == 0) return std::vector(arg, init); else return std::vector(arg, vec(init, args...)); } template auto vec(uns_t, Head arg, Args ...args) { return vec(Element(), arg, args...); } int main() { int n; cin >> n; auto a = vec(uns, n); for (auto &e : a) cin >> e; auto b = vec(uns, n, n); for (auto &e1 : b) for (auto &e2 : e1) cin >> e2; int64_t ans = INT64_MIN; int bits = 0; for (int i = 1; i < (1 << n); ++i) { int64_t cnt = 0; for (int j = 0; j < n; ++j) { if (!(i & (1 << j))) continue; cnt += a[j]; for (int k = j + 1; k < n; ++k) { if (!(i & (1 << k))) continue; cnt += b[j][k]; } } if (ans < cnt) { ans = cnt; bits = i; } } cout << ans << endl; int pos = 0; while (!(bits & (1 << pos))) { ++pos; } cout << pos + 1; while (++pos < n) { if (!(bits & (1 << pos))) continue; cout << ' ' << pos + 1; } cout << endl; }