#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  string str;
  cin >> str;
  int dp[10000] = {};
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (str[i] == '0') {
      int val = 0;
      for (int j = b; j < 10000; j += a) {
        if (val % 2 == 0)
          dp[j] += 1;
        else
          dp[j] -= 1;
        val++;
      }
    } else {
      int val = 0;
      dp[0] += 1;
      for (int j = b; j < 10000; j += a) {
        if (val % 2 != 0)
          dp[j] += 1;
        else
          dp[j] -= 1;
        val++;
      }
    }
  }
  for (int i = 1; i < 10000; i++) {
    dp[i] += dp[i - 1];
  }
  for (int i = 0; i < 10000; i++) ans = max(ans, dp[i]);
  cout << ans << endl;
  return 0;
}
