#include <bits/stdc++.h>
#pragma GCC optimize(3)
namespace orz {
inline void read(int &x) { scanf("%d", &x); }
inline void read(unsigned int &x) { scanf("%u", &x); }
inline void read(long long &x) { scanf("%I64d", &x); }
inline void read(unsigned long long &x) { scanf("%I64u", &x); }
inline void read(double &x) { scanf("%lf", &x); }
inline void read(long double &x) {
  double tmp;
  read(tmp);
  x = tmp;
}
inline void read(char &x) { x = getchar(); }
inline void read(char *x) { scanf("%s", x); }
template <class T>
inline void read(T *a, int n) {
  for (int i = (0); i < (n); ++i) read(a[i]);
}
template <class T1, class T2>
inline void read(T1 &a, T2 &b) {
  read(a);
  read(b);
}
template <class T1, class T2, class T3>
inline void read(T1 &a, T2 &b, T3 &c) {
  read(a);
  read(b);
  read(c);
}
template <class T1, class T2, class T3, class T4>
inline void read(T1 &a, T2 &b, T3 &c, T4 &d) {
  read(a);
  read(b);
  read(c);
  read(d);
}
template <class T1, class T2, class T3, class T4, class T5>
inline void read(T1 &a, T2 &b, T3 &c, T4 &d, T5 &e) {
  read(a);
  read(b);
  read(c);
  read(d);
  read(e);
}
inline void write(int x) { printf("%d", x); }
inline void write(unsigned int x) { printf("%u", x); }
inline void write(long long x) { printf("%I64d", x); }
inline void write(unsigned long long x) { printf("%I64u", x); }
inline void write(double x) { printf("%.10lf", x); }
inline void write(long double x) { printf("%.10lf", (double)x); }
inline void write(char x) { putchar(x); }
inline void write(char *x) { printf("%s", x); }
template <class T>
inline void writes(T x) {
  write(x);
  putchar(' ');
}
template <class T1, class T2>
inline void writes(T1 a, T2 b) {
  writes(a);
  writes(b);
}
template <class T1, class T2, class T3>
inline void writes(T1 a, T2 b, T3 c) {
  writes(a);
  writes(b);
  writes(c);
}
template <class T1, class T2, class T3, class T4>
inline void writes(T1 a, T2 b, T3 c, T4 d) {
  writes(a);
  writes(b);
  writes(c);
  writes(d);
}
template <class T1, class T2, class T3, class T4, class T5>
inline void writes(T1 a, T2 b, T3 c, T4 d, T5 e) {
  writes(a);
  writes(b);
  writes(c);
  writes(d);
  writes(e);
}
template <class T1, class T2>
inline void writesln(T1 a, T2 b) {
  writes(a);
  writes(b);
  putchar('\n');
}
template <class T1, class T2, class T3>
inline void writesln(T1 a, T2 b, T3 c) {
  writes(a);
  writes(b);
  writes(c);
  putchar('\n');
}
template <class T1, class T2, class T3, class T4>
inline void writesln(T1 a, T2 b, T3 c, T4 d) {
  writes(a);
  writes(b);
  writes(c);
  writes(d);
  putchar('\n');
}
template <class T1, class T2, class T3, class T4, class T5>
inline void writesln(T1 a, T2 b, T3 c, T4 d, T5 e) {
  writes(a);
  writes(b);
  writes(c);
  writes(d);
  writes(e);
  putchar('\n');
}
template <class T1, class T2>
inline void writeln(T1 a, T2 b) {
  write(a);
  write(b);
  putchar('\n');
}
template <class T1, class T2, class T3>
inline void writeln(T1 a, T2 b, T3 c) {
  write(a);
  write(b);
  write(c);
  putchar('\n');
}
template <class T1, class T2, class T3, class T4>
inline void writeln(T1 a, T2 b, T3 c, T4 d) {
  write(a);
  write(b);
  write(c);
  write(d);
  putchar('\n');
}
template <class T1, class T2, class T3, class T4, class T5>
inline void writeln(T1 a, T2 b, T3 c, T4 d, T5 e) {
  write(a);
  write(b);
  write(c);
  write(d);
  write(e);
  putchar('\n');
}
template <class T1, class T2>
inline void write(T1 a, T2 b) {
  write(a);
  write(b);
}
template <class T1, class T2, class T3>
inline void write(T1 a, T2 b, T3 c) {
  write(a);
  write(b);
  write(c);
}
template <class T1, class T2, class T3, class T4>
inline void write(T1 a, T2 b, T3 c, T4 d) {
  write(a);
  write(b);
  write(c);
  write(d);
}
template <class T1, class T2, class T3, class T4, class T5>
inline void write(T1 a, T2 b, T3 c, T4 d, T5 e) {
  write(a);
  write(b);
  write(c);
  write(d);
  write(e);
}
template <class T>
inline void writeln(T x) {
  write(x);
  putchar('\n');
}
template <class T>
inline void writeln(T *a, int n) {
  for (int i = (0); i < (n); ++i) write(a[i]);
  putchar('\n');
}
template <class T>
inline void writesln(T *a, int n) {
  for (int i = (0); i < (n); ++i) writes(a[i]);
  putchar('\n');
}
template <class T>
inline void writelnln(T *a, int n) {
  for (int i = (0); i < (n); ++i) writeln(a[i]);
}
}  // namespace orz
using namespace orz;
int n, x[233], y[233], z[233];
char a[233][233];
bool b[233], use[233];
int main() {
  srand(time(0));
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i) scanf("%s", a[i] + 1);
  for (int i = (1); i <= (n); ++i)
    for (int j = (1); j <= (n); ++j) a[i][j] -= '0';
  for (int i = (1); i <= (n); ++i) scanf("%d", x + i);
  for (int i = (1); i <= (n); ++i) z[i] = i;
  for (;;) {
    std::random_shuffle(z + 1, z + n + 1);
    memset(y, 0, sizeof(y));
    memset(b, 0, sizeof(b));
    for (;;) {
      bool change = false;
      memset(use, 0, sizeof(use));
      for (int i = (1); i <= (n); ++i)
        if (x[i] == y[i])
          for (int j = (1); j <= (n); ++j)
            if (!b[j] && a[j][i]) use[j] = true;
      for (int i = (1); i <= (n); ++i) {
        int c = z[i];
        if (use[c]) {
          for (int j = (1); j <= (n); ++j)
            if (a[c][j]) ++y[j];
          b[c] = 1;
          change = true;
          break;
        }
      }
      if (!change) break;
    }
    bool ok = true;
    for (int i = (1); i <= (n); ++i)
      if (x[i] == y[i]) {
        ok = false;
        break;
      }
    if (ok) {
      int m = 0;
      for (int i = (1); i <= (n); ++i)
        if (b[i]) ++m;
      printf("%d\n", m);
      bool first = true;
      for (int i = (1); i <= (n); ++i)
        if (b[i]) {
          if (first)
            first = false;
          else
            putchar(' ');
          printf("%d", i);
        }
      printf("\n");
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
