#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
template <class T>
inline bool read(T &n) {
  T x = 0, tmp = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
  if (c == EOF) return false;
  if (c == '-') c = getchar(), tmp = -1;
  while (c >= '0' && c <= '9') x *= 10, x += (c - '0'), c = getchar();
  n = x * tmp;
  return true;
}
template <class T>
inline void write(T n) {
  if (n < 0) {
    putchar('-');
    n = -n;
  }
  int len = 0, data[20];
  while (n) {
    data[len++] = n % 10;
    n /= 10;
  }
  if (!len) data[len++] = 0;
  while (len--) putchar(data[len] + 48);
}
int n, a[111][111];
int cnt[111];
vector<int> ans;
vector<pair<int, int> > pe;
int main() {
  scanf("%d", &n);
  pe.resize(n + 11);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) scanf("%1d", &a[i][j]);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &pe[i].first);
    pe[i].second = i;
  }
  sort(pe.begin() + 1, pe.begin() + n + 1);
  int flag = 1, num = 0;
  while (flag) {
    flag = 0;
    num++;
    for (int i = 1; i <= n; i++)
      if (cnt[pe[i].second] == pe[i].first) {
        flag = 1;
        ans.push_back(pe[i].second);
        for (int j = 1; j <= n; j++)
          if (a[pe[i].second][j]) cnt[j]++;
      }
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]);
  return 0;
}
