#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                         {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
int main() {
  srand((unsigned int)time(NULL));
  int n;
  int a[102][102];
  int b[102];
  char c[102][102];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("\n");
    for (int j = 0; j < n; j++) {
      scanf("%c", &c[i][j]);
      if (c[i][j] == '0')
        a[i][j] = 0;
      else
        a[i][j] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
  }
  int p[102] = {};
  while (1) {
  NEXT:;
    int cnt[102] = {};
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cnt[j] += p[i] * a[i][j];
      }
    }
    for (int i = 0; i < n; i++) {
      if (cnt[i] == b[i]) {
        p[i]++;
        goto NEXT;
      }
    }
    int ret = 0;
    for (int i = 0; i < n; i++) {
      ret += p[i];
    }
    printf("%d\n", ret);
    for (int i = 0; i < n; i++) {
      if (p[i] == 1) {
        printf("%d", i + 1);
        ret--;
        if (ret != 0) printf(" ");
      }
    }
    puts("");
    return 0;
  }
  puts("-1");
}
