#include <bits/stdc++.h>
using namespace std;
int func(bool first, int a, int b, int time) {
  if (time < b) return first ? 1 : 0;
  time -= b;
  first = !first;
  int x = time / a;
  if (x % 2 == 0) return first ? 1 : 0;
  return !first ? 1 : 0;
}
int main() {
  int n;
  cin >> n;
  char c;
  vector<bool> mask(n);
  for (int i = 0; i < n; ++i) {
    cin >> c;
    if (c == '1')
      mask[i] = true;
    else
      mask[i] = false;
  }
  vector<pair<int, int>> ab(n);
  for (int i = 0; i < n; ++i) {
    cin >> ab[i].first >> ab[i].second;
  }
  int max_cnt = 0;
  for (int i = 0; i < 10000; ++i) {
    int cnt = 0;
    for (int j = 0; j < n; ++j) {
      cnt += func(mask[j], ab[j].first, ab[j].second, i);
    }
    max_cnt = max(max_cnt, cnt);
  }
  cout << max_cnt;
  return 0;
}
