#include #define rep(i,n) for(int i = 0; i < (n); ++i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) using namespace std; typedef long long int ll; typedef pair P; #define yn {puts("YES");}else{puts("NO");} #define MAX_N 200005 int main() { int n; cin >> n; ll a[n] = {}; rep(i,n) cin >> a[i]; ll b[n][n]; rep(i,n)rep(j,n)cin >> b[i][j]; ll ans = -1; vector arg; rep(i,1< bi(i); ll sum = 0; rep(j,n) sum += a[j] * bi[j]; rep(j,n) srep(k,j+1,n) sum += b[j][k] * bi[j] * bi[k]; if(ans < sum){ ans = sum; arg.clear(); rep(j,n) if(bi[j]) arg.push_back(j+1); } } cout << ans << endl; rep(i,arg.size()){ if(i == arg.size() - 1) cout << arg[i] << endl; else cout << arg[i] << ' '; } return 0; }