#include <bits/stdc++.h>
using namespace std;
int n;
bool p, f[101][101], bz[101];
int a[101], b[101], d[101], ans[101];
void init() {
  static char c;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) scanf(" %c", &c), f[i][j] = c - '0';
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
}
void dfs() {
  for (int i = 1; i <= n; i++)
    if (b[i] == a[i]) {
      for (int j = 1; j <= n && !p; j++)
        if (f[j][i] && !bz[j]) {
          for (int k = 1; k <= n; k++) b[k] += f[j][k];
          d[++d[0]] = j;
          bz[j] = 1;
          dfs();
          --d[0], bz[j] = 0;
          for (int k = 1; k <= n; k++) b[k] -= f[j][k];
        }
      return;
    }
  p = true;
  for (int i = 0; i <= d[0]; i++) ans[i] = d[i];
}
void work() { dfs(); }
void write() {
  if (p) {
    printf("%d\n", ans[0]);
    for (int i = 1; i <= ans[0]; i++) printf("%d ", ans[i]);
  } else
    printf("-1");
}
int main() {
  init();
  work();
  write();
  return 0;
}
