#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  return (a / gcd(a, b)) * b;
}
int main() {
  long long int n;
  cin >> n;
  string s;
  cin >> s;
  long long int in[n][2];
  long long int mul = in[0][0];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> in[i][j];
    }
  }
  long long int maxi = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') {
      maxi++;
    }
  }
  long long int arr[n][10000];
  for (int i = 0; i < n; i++) {
    bool on;
    if (s[i] == '0') {
      on = false;
    } else {
      on = true;
    }
    long long int a = in[i][0], b = in[i][1];
    for (int j = 0; j < 10000; j++) {
      if (j + 1 == b) {
        b += a;
        if (on) {
          on = false;
        } else {
          on = true;
        }
      }
      if (on) {
        arr[i][j] = 1;
      } else {
        arr[i][j] = 0;
      }
    }
  }
  for (int j = 0; j < 10000; j++) {
    long long int count = 0;
    for (int i = 0; i < n; i++) {
      if (arr[i][j] == 1) {
        count++;
      }
    }
    maxi = max(maxi, count);
  }
  cout << maxi;
}
