#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<pair<int, int> > v(n);
  string s;
  cin >> s;
  vector<bool> p0(n, 0);
  for (int i = 0; i < n; i++)
    if (s[i] == '1') p0[i] = 1;
  for (auto &i : v) cin >> i.first >> i.second;
  vector<int> num((int)1e6 + 6, 0);
  int a, d;
  for (int i = 0; i < n; i++) {
    a = v[i].second;
    d = v[i].first;
    bool on = p0[i];
    if (p0[i]) num[0]++;
    for (int k = 1, j = 0; k < 1000; k++) {
      if (k == a + j * d) {
        on = !on;
        j++;
      }
      if (on) num[k]++;
    }
  }
  int mx = 0;
  for (int i = 0; i < 1000; i++) mx = max(mx, num[i]);
  cout << mx << endl;
}
void solve_2() {
  int t;
  cin >> t;
  while (t--) solve();
}
int main() {
  solve();
  return 0;
}
