#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; int N, A[20], B[20][20], sum, ans, ansi; int main() { cin >> N; for (int i = 1; i <= N; i++) cin >> A[i]; for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) cin >> B[i][j]; } for (int i = 1; i < (1 << N); i++) { sum = 0; for (int j = 0; j < N; j++) { if (i >> j & 1) { sum += A[j + 1]; } } for (int j = 0; j < N; j++) { for (int k = j + 1; k < N; k++) { if ((i >> j & 1) && (i >> k & 1)) { sum += B[j + 1][k + 1]; } } } if (ans < sum) { ans = sum; ansi = i; } } cout << ans << endl; vector vec; for (int i = 0; i < N; i++) { if (ansi >> i & 1) { vec.push_back(i + 1); } } for (int i = 0; i < vec.size(); i++) cout << vec[i] << " \n"[i == vec.size() - 1]; return 0; }