#include #include using namespace atcoder; using namespace std; using ll=long long; using ld=long double; ld pie=3.141592653589793; ll mod=998244353 ; ll inf=10000999999999900; int main(){ ll n; cin >> n; vectora(n); for (ll i = 0; i < n; i++) { cin >> a[i]; } vector>b(n,vector(n)); for (ll i = 0; i < n; i++) { for (ll j = 0; j < n; j++) { cin >> b[i][j]; } } vectortwo(30,1); for (ll i = 1; i < 30; i++) { two[i]=two[i-1]*2; } ll ans=0; ll x=0; for (ll i = 1; i < two[n]; i++) { ll y=0; for (ll j = 0; j < n; j++) { if (two[j]&i) { y+=a[j]; } } for (ll j = 0; j < n; j++) { for (ll k = 0; k < n; k++) { if (two[j]&i&&two[k]&i) { y+=b[j][k]; } } } if (y>ans) { ans=y; x=i; } } cout << ans << endl; for (ll i = 0; i < n; i++) { if (two[i]&x) { cout << i+1 << ' '; } } }