#include <bits/stdc++.h>
using namespace std;
int a[1001][1001], b[1000001], cur[1000001];
int main() {
  int i, j, n, s;
  vector<int> ans;
  string str;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> str;
    str = " " + str;
    for (j = 1; j <= n; j++) a[i][j] = str[j] - '0';
  }
  for (i = 1; i <= n; i++) cin >> b[i];
  while (1) {
    s = -1;
    for (i = 1; i <= n; i++) {
      if (cur[i] == b[i]) {
        s = i;
        break;
      }
    }
    if (s == -1) break;
    ans.push_back(s);
    for (i = 1; i <= n; i++) {
      if (a[s][i]) cur[i]++;
    }
  }
  cout << ans.size() << endl;
  for (i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  return 0;
}
