#include #include #include #include #include #include #include #include #include #include using namespace std; int main() { long long n, max1=-1; bitset<18> maxbit; cin >> n; vector a(n); vector> b(n, vector(n)); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ cin >> b[i][j]; } } for (int tmp = 0; tmp < (1 << 18); tmp++){ bitset<18> s(tmp); long long sum1 = 0; for (int i = 0; i < n; i++){ if (s.test(i)){ sum1 += a[i]; if (i != n-1){ for (int j = i; j < n; j++){ if(s.test(j)){ sum1 += b[i][j]; } } } } } if (sum1 > max1){ max1 = sum1; maxbit = s; } } cout << max1 << "\n"; string delim = ""; for (int i = 0; i < 18; i++){ if (maxbit.test(i)){ cout << delim << i+1; delim = " "; } } cout << endl; }