#include <bits/stdc++.h>
using namespace std;
long long d, x, y;
void extendedEuclid(long long A, long long B) {
  if (B == 0) {
    d = A;
    x = 1;
    y = 0;
  } else {
    extendedEuclid(B, A % B);
    int temp = x;
    x = y;
    y = temp - (A / B) * y;
  }
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long IsPrime(long long n) {
  if (n == 0 || n == 1) return n;
  if (n % 2 == 0) return (long long)2;
  if (n % 3 == 0)
    return (long long)3;
  else {
    for (long long i = 5; i * i <= n; i += 6) {
      if (n % i == 0) return i;
      if (n % (i + 2) == 0) return (i + 2);
    }
    return n;
  }
}
long long ans = 0;
vector<vector<long long> > v(100010);
vector<long long> vis(100010, 0), yes(100010, 0), par(100010);
vector<long long> temp(100010), f(100010), g(100010);
void dfs(long long n) {
  vis[n] = 1;
  for (long long i = 0; i < v[n].size(); i++) {
    if (!vis[v[n][i]]) {
      par[v[n][i]] = n;
      dfs(v[n][i]);
    }
  }
  f[n] = yes[n];
  for (long long i = 0; i < v[n].size(); i++) {
    if (par[n] != v[n][i]) temp.push_back(f[v[n][i]]);
  }
  sort(temp.rbegin(), temp.rend());
  if (temp.size() > 0) f[n] += temp[0];
  if (temp.size() > 1) g[n] = f[n] + temp[1];
  ans = max(ans, max(f[n], g[n]));
  temp.clear();
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m, k, i, j;
  cin >> n;
  string s;
  cin >> s;
  vector<long long> ans(100000, 0);
  for (i = 0; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    k = s[i] - '0';
    for (j = 0; j < b; j++) ans[j] += k;
    long long c = 0;
    k = (k + 1) % 2;
    for (j = b; j < 10000; j++) {
      ans[j] += k;
      c++;
      if (c == a) {
        k = (k + 1) % 2;
        c = 0;
      }
    }
  }
  long long an = 0;
  for (i = 0; i < 10000; i++) an = max(an, ans[i]);
  cout << an;
}
