#include <bits/stdc++.h>
using namespace std;
class node {
 public:
  vector<int> near;
};
node a[110];
int cnt[110];
bool done[110] = {0};
vector<int> solve(vector<int> v) {
  vector<int> z, rem;
  for (int i = 0; i < v.size(); i++) {
    if (cnt[v[i]] == 0)
      z.push_back(v[i]);
    else
      rem.push_back(v[i]);
  }
  if (z.size() == 0) return z;
  vector<int> res;
  for (int i = 0; i < z.size(); i++) {
    int x = z[i];
    vector<int> ne = a[x].near;
    for (int j = 0; j < ne.size(); j++) {
      cnt[ne[j]]--;
    }
  }
  vector<int> xf = solve(rem);
  vector<int> answer;
  for (int i = 0; i < xf.size(); i++) answer.push_back(xf[i]);
  for (int i = 0; i < z.size(); i++) answer.push_back(z[i]);
  return answer;
}
int cnt1[110];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    for (int j = 1; j <= n; j++) {
      if (s[j - 1] == '1') a[i].near.push_back(j);
    }
  }
  for (int i = 1; i <= n; i++) {
    cin >> cnt[i];
    cnt1[i] = cnt[i];
  }
  vector<int> u;
  for (int i = 1; i <= n; i++) u.push_back(i);
  vector<int> v = solve(u);
  for (int i = 1; i <= n; i++) cnt[i] = 0;
  for (int i = 0; i < v.size(); i++) {
    vector<int> xf = a[v[i]].near;
    for (int j = 0; j < xf.size(); j++) cnt[xf[j]]++;
  }
  bool psbl = 1;
  for (int i = 1; i <= n; i++) {
    if (cnt[i] == cnt1[i]) psbl = 0;
  }
  if (!psbl) {
    cout << -1 << endl;
    return 0;
  }
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
  cout << endl;
}
