#include <bits/stdc++.h>
using namespace std;
bool b[105][105];
char c[1005];
int s[1005];
int a[1005];
queue<int> q;
set<int> inv;
int main(void) {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> (c + 1);
    for (int j = 1; j <= n; ++j) b[i][j] = c[j] - '0';
  }
  bool ok = 1;
  for (int i = 1; i <= n; ++i) cin >> s[i], ok &= bool(s[i]);
  if (ok) return cout << "0\n", 0;
  for (int i = 1; i <= n; ++i)
    if (!s[i]) {
      inv.insert(i);
      for (int j = 1; j <= n; ++j)
        if (b[i][j]) ++a[j];
    }
  int ans = 0;
  ok = 1;
  for (int i = 1; i <= n; ++i)
    if (a[i] == s[i] && inv.find(i) == inv.end()) q.push(i), ok = 0;
  while (!ok) {
    while (q.size()) {
      int top = q.front();
      q.pop();
      inv.insert(top);
      for (int i = 1; i <= n; ++i)
        if (b[top][i]) ++a[i];
    }
    ok = 1;
    for (int i = 1; i <= n; ++i)
      if (a[i] == s[i] && inv.find(i) == inv.end()) q.push(i), ok = 0;
  }
  for (int i = 1; i <= n; ++i)
    if (a[i] == s[i]) return cout << "-1\n", 0;
  cout << inv.size() << '\n';
  for (set<int>::iterator it = inv.begin(); it != inv.end(); ++it)
    cout << *it << ' ';
  return cout << '\n', 0;
}
