#include using namespace std; using ll = long long; using ld = long double; const ld pi = 3.14159265358979; const int mod = 1000000007; 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 = 0; vectorans_bit; for(int i = 1; i < (1 << n); i++){ ll cost = 0; vector now; for(int j = 0; j < n; j++){ if(i & (1 << j)){ cost += (ll)a[j]; now.push_back(j); //cout << 1 << " "; }else{ //cout << 0 << " "; } } if(now.size() >= 2){ for(int x = 0; x < now.size(); x++){ for(int y = x; y < now.size(); y++){ cost += (ll)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; }