#include <bits/stdc++.h>
using namespace std;
int n, e[105][105], vis[105], deg[105], a[105];
void bfs() {
  queue<int> q;
  for (int i = 1; i <= n; ++i)
    if (a[i] == 0) q.push(i);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (int i = 1; i <= n; ++i)
      if (e[u][i]) deg[i]++;
    for (int i = 1; i <= n; ++i)
      if (deg[i] == a[i]) q.push(i);
  }
}
signed main() {
  cin >> n;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) {
      char ch;
      cin >> ch;
      e[i][j] = ch - '0';
    }
  for (int i = 1; i <= n; ++i) cin >> a[i];
  bfs();
  for (int i = 1; i <= n; ++i)
    if (deg[i] == a[i]) return cout << -1, 0;
  int cnt = 0;
  for (int i = 1; i <= n; ++i) cnt += vis[i];
  cout << cnt << endl;
  for (int i = 1; i <= n; ++i)
    if (vis[i]) cout << i << " ";
}
