#line 1 "main.cpp" #include #include using namespace std; using lint = long long; void solve() { int n; cin >> n; vector xs(n); for (auto& x : xs) cin >> x; auto yss = vector(n, vector(n, 0LL)); for (auto& ys : yss) { for (auto& y : ys) cin >> y; } lint ma = -1; int mb = 0; for (int b = 1; b < (1 << n); ++b) { lint s = 0; for (int i = 0; i < n; ++i) { if ((b >> i) & 1) s += xs[i]; } for (int i = 0; i < n; ++i) { if ((~b >> i) & 1) continue; for (int j = 0; j < i; ++j) { if ((~b >> j) & 1) continue; s += yss[i][j]; } } if (s > ma) { ma = s; mb = b; } } cout << ma << "\n"; for (int i = 0; i < n; ++i) { if ((mb >> i) & 1) cout << i + 1 << " "; } cout << "\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }