#include <bits/stdc++.h>
using namespace std;
bool codejam = 0;
void solve();
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(20);
  long long t = 1;
  long long tt = t;
  while (t--) {
    if (codejam) cout << "Case #" << tt - t << ": ";
    solve();
  }
  return 0;
}
long long n;
long long g[105][105];
long long arr[105];
bool inv[105] = {false};
long long rec[105] = {0};
void solve() {
  cin >> n;
  for (long long i = 1; i <= n; i += 1) {
    for (long long j = 1; j <= n; j += 1) {
      char c;
      cin >> c;
      if (c == '1')
        g[i][j] = 1;
      else
        g[i][j] = 0;
    }
  }
  bool ok = true;
  for (long long i = 1; i <= n; i += 1) {
    cin >> arr[i];
    if (arr[i] == 0) ok = false;
  }
  if (ok) {
    cout << 0;
    return;
  }
  for (long long step = 0; step < n; ++step) {
    bool found = false;
    long long which;
    for (long long i = 1; i <= n; ++i) {
      if (inv[i]) continue;
      if (rec[i] == arr[i]) {
        found = true;
        which = i;
      }
    }
    if (!found) break;
    inv[which] = true;
    for (long long j = 1; j <= n; ++j) {
      if (g[which][j]) rec[j]++;
    }
  }
  for (long long i = 1; i <= n; i++) {
    if (rec[i] == arr[i]) {
      cout << -1;
      return;
    }
  }
  long long cnt = 0;
  for (long long i = 1; i <= n; i++)
    if (inv[i]) cnt++;
  cout << cnt << '\n';
  for (long long i = 1; i <= n; i++)
    if (inv[i]) cout << i << ' ';
}
