#include <bits/stdc++.h>
using namespace std;
const int maxN = 100 + 5;
const int mod = 1000 * 1000 * 1000 + 7;
const int maxM = 400000;
char a[102][102];
int c[maxN], cnt[maxN], p[maxN];
int main() {
  ios::sync_with_stdio(0);
  cin.tie();
  srand(time(NULL));
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) cin >> a[i][j];
  for (int i = 0; i < n; i++) cin >> c[i];
  set<pair<int, int> > ss;
  for (int i = 0; i < n; i++) ss.insert({c[i], i});
  vector<int> ans;
  while (ss.size()) {
    while (ss.size() && ss.begin()->first < 0) ss.erase(ss.begin());
    if (ss.size() == 0 || ss.begin()->first > 0) break;
    auto it = *ss.begin();
    int v = it.second;
    ans.push_back(v);
    for (int i = 0; i < n; i++)
      if (a[v][i] == '1' && c[i] >= 0) {
        ss.erase({c[i], i});
        c[i]--;
        ss.insert({c[i], i});
      }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) cout << ans[i] + 1 << ' ';
  cout << endl;
  return 0;
}
