#include <bits/stdc++.h>
using namespace std;

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<28)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define MOD (1000000007)
#define TO_STRING(VariableName) # VariableName
#define LOG(xx) if(DEBUG)cout<<TO_STRING(xx)<<"="<<xx<<" "<<endl;
#define LOG2(xx,yy) if(DEBUG)cout<<TO_STRING(xx)<<"="<<xx<<" "<<TO_STRING(yy)<<"="<<yy<<endl;
#define LOG3(xx,yy,z) if(DEBUG)cout<<TO_STRING(xx)<<"="<<xx<<" "<<TO_STRING(yy)<<"="<<yy<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,xx,yy,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(xx)<<"="<<xx<<" "<<TO_STRING(yy)<<"="<<yy<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

lli dd[20][20];

lli b[20][20];

int main(){

    lli n;
    cin>>n;
    vector<lli> a(n);
    REP(i,0,n)cin>>a[i];

    REP(i,0,n)REP(j,0,n)cin>>b[i][j];

    lli ans = 0;
    vector<lli> ansV;
    for(lli i=0;i<(1LL<<n);i++){
        vector<lli> c;
        lli score = 0;
        for(lli j=0;j<n;j++){
            if(i&(1LL<<j)){
                score += a[j];
                c.push_back(j);
            }
        }
        for(lli x = 0;x<c.size();x++){
            for(lli y=x+1;y<c.size();y++){
                score += b[c[x]][c[y]];
            }
        }
        if(score >= ans){
            ans = score;
            ansV = c;
        }
    }
    cout<<ans<<endl;
    REP(i,0,ansV.size()){
        cout<<ansV[i]+1;
        if(i!=ansV.size()-1)cout<<" ";
        else cout<<endl;
    }


    return 0;
}