#include <bits/stdc++.h>
using namespace std;
string m[200];
int ans[200];
int ans_count = 0;
int b[200];
int main() {
  int n;
  cin >> n;
  for (int(i) = (0); (i) < (int)(n); ++(i)) {
    cin >> m[i];
  }
  for (int(i) = (0); (i) < (int)(n); ++(i)) {
    cin >> b[i];
    b[i] = -b[i];
  }
  for (int(_) = (0); (_) < (int)(n); ++(_)) {
    for (int(i) = (0); (i) < (int)(n); ++(i)) {
      if (b[i] == 0) {
        for (int(j) = (0); (j) < (int)(n); ++(j)) {
          if (ans[j] == 0 && m[j][i] == '1') {
            ans_count++;
            ans[j] = 1;
            for (int(k) = (0); (k) < (int)(n); ++(k)) {
              b[k] += (m[j][k] == '1');
            }
            break;
          }
        }
      }
    }
  }
  int ok = 1;
  for (int(i) = (0); (i) < (int)(n); ++(i)) {
    ok &= (b[i] != 0);
  }
  if (!ok) {
    printf("-1\n");
  } else {
    printf("%d\n", ans_count);
    for (int(i) = (0); (i) < (int)(n); ++(i)) {
      if (ans[i]) {
        printf("%d ", i + 1);
      }
    }
    printf("\n");
  }
  return 0;
}
