#include #include using namespace std; using ll = long long; int main() { int N; cin >> N; vector A(N); vector > B(N,vector(N)); ll max; ll score; vector v; vector arg; for (int i = 0; i < N; i++) { cin >> A.at(i); } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cin >> B.at(i).at(j); } } max = -1; arg = {}; for (int x = 1; x < (1 << N); x++) { v = {}; for (int k = 0; k < N; k++) { if (x & (1 << k)) { v.push_back(k); } } score = 0; for (int i = 0; i < v.size(); i++) { score += A.at(v.at(i)); } for (int i = 0; i < v.size(); i++) { for (int j = i + 1; j < v.size(); j++) { score += B.at(v.at(i)).at(v.at(j)); } } if (max < score) { max = score; arg = {}; for (int i = 0; i < v.size(); i++) { arg.push_back(v.at(i)); } } } cout << max << " " << arg.size() << endl; for (int i = 0; i < arg.size(); i++) { cout << arg.at(i) + 1; if (i != arg.size() - 1) { cout << " "; } else { cout << endl; } } return 0; }