#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
const int maxm = 1005;
int n;
int rec[maxn];
int igor[maxn];
vector<int> to[maxn];
vector<int> ctn[maxn];
char buf[maxn];
vector<int> come;
bool iscome[maxn];
void add(int id) {
  iscome[id] = true;
  come.push_back(id);
  int len = to[id].size();
  for (int i = 0; i < len; i++) {
    rec[to[id][i]]++;
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%s", buf + 1);
    for (int j = 1; j <= n; j++) {
      if (buf[j] == '1') {
        to[i].push_back(j);
        ctn[j].push_back(i);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &igor[i]);
  }
  memset(iscome, false, sizeof(iscome));
  bool igorwin = false;
  while (true) {
    bool isadd = false;
    bool somecome = false;
    for (int i = 1; i <= n; i++) {
      if (rec[i] == igor[i]) {
        isadd = true;
        int len = ctn[i].size();
        somecome = false;
        for (int j = 0; j < len; j++) {
          if (!iscome[ctn[i][j]]) {
            add(ctn[i][j]);
            somecome = true;
            break;
          }
        }
      }
    }
    if (isadd && somecome) {
      continue;
    } else if (isadd) {
      igorwin = true;
      break;
    } else
      break;
  }
  if (igorwin) {
    puts("-1");
    return 0;
  }
  cout << come.size() << endl;
  int len = come.size();
  for (int i = 0; i < len; i++) {
    printf("%d ", come[i]);
  }
  puts("");
}
