#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #pragma warning(disable:4996) //#define ATCODER #ifdef ATCODER #include #endif typedef long long ll; typedef unsigned long long ull; #define LINF 9223300000000000000 #define LINF2 1223300000000000000 #define LINF3 1000000000000 #define INF 2140000000 //const long long MOD = 1000000007; const long long MOD = 998244353; using namespace std; #ifdef ATCODER using namespace atcoder; #endif ll a[18]; ll b[18][18]; void solve() { int n; scanf("%d", &n); int i, j, k; for (i = 0; i < n; i++) { scanf("%lld", &a[i]); } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%lld", &b[i][j]); } } ll ans = -LINF; int maxi = -1; for (i = 0; i < (1 << n); i++) { ll ans0 = 0; for (j = 0; j < n; j++) { if (i & (1 << j)) ans0 += a[j]; } for (j = 0; j < n; j++) { if (i & (1 << j)) { for (k = j + 1; k < n; k++) { if (i & (1 << k)) ans0 += b[j][k]; } } } if (ans0 > ans) { ans = ans0; maxi = i; } } printf("%lld\n", ans); vector v; for (i = 0; i < n; i++) { if (maxi & (1 << i)) v.push_back(i); } for (i = 0; i < (int)v.size(); i++) { printf("%d", v[i]+1); if (i < (int)v.size() - 1) printf(" "); else printf("\n"); } return; } int main() { #if 1 solve(); #else int T, t; scanf("%d",&T); for (t = 0; t < T; t++) { //cout << "Case #" << t + 1 << ": "; solve(); } #endif return 0; }