#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const int MAX = 300 + 10;
char mapp[MAX][MAX];
int cnt[MAX];
bool vis[MAX];
int n, s[MAX], ans;
int main() {
  memset(cnt, 0, sizeof(cnt));
  memset(vis, 0, sizeof(vis));
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%s", mapp[i]);
  }
  int juge = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &s[i]);
    if (s[i] == 0) juge = 0;
  }
  if (juge) {
    cout << "0" << endl;
    return 0;
  }
  juge = 0;
  ans = 0;
  while (1) {
    int temp = -1, k;
    for (int k = 1; k <= n; k++) {
      if (vis[k] == 0) break;
    }
    if (k == n + 1) break;
    for (int i = 1; i <= n; i++) {
      if (cnt[i] == s[i]) {
        if (vis[i])
          continue;
        else
          vis[i] = 1;
        temp = i;
        ans++;
        break;
      }
    }
    if (temp == -1) break;
    for (int i = 0; i <= n; i++) {
      if (mapp[temp][i] == '1') {
        cnt[i + 1]++;
      }
    }
    for (k = 1; k <= n; k++) {
      if (s[k] == cnt[k]) break;
    }
    if (k == n + 1) {
      juge = 1;
      break;
    }
  }
  if (juge == 0) {
    cout << "-1" << endl;
  } else {
    juge = 0;
    cout << ans << endl;
    for (int i = 1; i <= n; i++) {
      if (juge == 0 && vis[i]) {
        cout << i;
        juge = 1;
      } else if (vis[i])
        cout << " " << i;
    }
  }
  return 0;
}
