#include using namespace std; using ll = long long; using ld = long double; const ld pi = 3.14159265358979; const int mod = 1000000007; const ll inf = 123456789123456; int main(){ int n; cin >> n; vector a(n); for(int i = 0; i < n; i++){ cin >> a[i]; } vector> b(n , vector(n)); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ cin >> b[i][j]; } } ll ans = -inf; vectorans_bit; for(int i = 0; i < (1 << n); i++){ ll cost = 0; vector now; for(int j = 0; j < n; j++){ if(i & (1 << j)){ cost += a[j]; now.push_back(j); } } //cout << bitset<20>(i) << endl; for(int x = 0; x < now.size(); x++){ for(int y = x; y < now.size(); y++){ cost += b[x][y]; } } if(cost >= ans){ ans = cost; ans_bit = now; } } cout << ans << endl; for(int i = 0; i < ans_bit.size(); i++){ cout << ans_bit[i] + 1; if(i != ans_bit.size() - 1)cout << " "; else cout << endl; } return 0; }