#include using namespace std; int main() { int N; cin >> N; vector A( N ); vector> B( N, vector( N ) ); for( int i = 0; i < N; i++ ) cin >> A[i]; for( int i = 0; i < N; i++ ) { for( int j = 0; j < N; j++ ) cin >> B[i][j]; } int l = 1 << N; long long ans = 0; vector av; for( int mask = 0; mask < l; mask++ ) { long long s = 0; vector d; for( int i = 0; i < N; i++ ) { if( mask >> i & 1 ) { s += A[i]; d.push_back( i ); } } for( int i = 0; i < d.size(); i++ ) { for( int j = i + 1; j < d.size(); j++ ) s += B[i][j]; } if( s > ans ) { ans = s; av = d; } } cout << ans << endl; for( int i = 0; i < av.size(); i++ ) { if( i ) cout << " "; cout << av[i] + 1; } cout << endl; }