#include <bits/stdc++.h>
using namespace std;
int num[110], to[110][110], cnt, n, ans[110];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) scanf("%1d", &to[i][j]);
  for (int i = 1; i <= n; i++) scanf("%d", &num[i]);
  int flag = 0, t = 0;
  while (1) {
    ++t, flag = 0;
    for (int i = 1; i <= n; i++)
      if (num[i] == 0 && ans[i] == 0) {
        ans[i] = 1, cnt++;
        for (int j = 1; j <= n; j++)
          if (to[i][j] == 1) num[j]--;
        flag = 1;
        break;
      }
    if (flag == 0) break;
    if (t > n) {
      printf("-1\n");
      return 0;
    }
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= n; i++)
    if (ans[i]) printf("%d ", i);
}
