#include <bits/stdc++.h>
using namespace std;
int c[105], a[105], b[105], l[1000];
char c1[105];
int an = 0, n, sum;
void add(int a, int b, int c) {
  if (c == 1) {
    for (int i = 0; i < b; ++i) {
      l[i]++;
    }
    for (int i = b + a; i < 1000; i += 2 * a) {
      for (int j = i; j < 1000 && j < i + a; j++) {
        l[j]++;
      }
    }
    return;
  } else {
    for (int i = b; i < 1000; i += 2 * a) {
      for (int j = i; j < 1000 && j < i + a; j++) {
        l[j]++;
      }
    }
    return;
  }
}
int main() {
  cin >> n;
  getchar();
  for (int i = 0; i < n; ++i) {
    cin >> c1[i];
    c[i] = c1[i] - '0';
  }
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  memset(l, sizeof(l), 0);
  for (int i = 0; i < n; ++i) {
    add(a[i], b[i], c[i]);
  }
  for (int i = 0; i < 1000; ++i) {
    if (l[i] > an) {
      an = l[i];
    }
  }
  cout << an << endl;
  return 0;
}
