#include <bits/stdc++.h>
using namespace std;
int n, ans = 0;
int a[11];
int t[11], cnt = 1;
int mp[11][11];
int c = 0, Ans[11];
inline void work(int x)
{
cout << 1 << endl;
ans += a[x];
for(int i = x + 1; i <= n; i++)
if(mp[x][i])
{
t[++cnt] = i;
work(i);
}
}
int main()
{
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int i = 1; i <= n - 1; i++)
for(int j = i + 1; j <= n; j++)
{
cin >> mp[i][j];
mp[j][i] = mp[i][j];
}
for(int i = 1; i <= n; i++)
{
memset(t, 0, sizeof(t));
t[1] = 1;
cnt = 1;
ans = 0;
work(i);
if(ans > c)
{
c = ans;
Ans[1] = i;
for(int j = 2; j <= cnt; j++)
Ans[j] = t[j];
}
}
for(int i = 1; i <= cnt; i++)
cout << Ans[i] << " ";
cout << endl << ans;
return 0;
}