#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { int n; cin >> n; vector a(n); rep(i, n) cin >> a[i]; vector b(n, vector(n)); rep(i, n) rep(j, n) cin >> b[i][j]; pair ans = { -1e18, 0 }; rep(bit, 1 << n) { if (bit == 0) continue; ll sum = 0; rep(i, n) { if (bit & (1 << i)) sum += 2 * a[i]; } rep(i, n) rep(j, n) { if ((bit & (1 << i)) && (bit & (1 << j))) sum += b[i][j]; } if (sum / 2 > ans.first) ans = { sum / 2, bit }; } cout << ans.first << endl; rep(i, n) if (ans.second & (1 << i)) cout << i + 1 << ' '; cout << endl; return 0; }