#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e18;
bool prime[10009];
void SieveOfEratosthenes(long long n) {
  memset(prime, true, sizeof(prime));
  for (long long p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (long long i = p * p; i <= n; i += p) {
        prime[i] = false;
      }
    }
  }
}
long long power(long long x, long long y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return power(x, y / 2) * power(x, y / 2);
  else
    return x * power(x, y / 2) * power(x, y / 2);
}
long long power1(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      res *= a;
    }
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long mod_power(long long a, long long b, long long m) {
  long long res = 1;
  a %= m;
  while (b) {
    if (b & 1) {
      res = res * a % m;
    }
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
long long printDivisors(long long n) {
  long long count = 0;
  for (long long i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        count++;
      else
        printf("%d %d ", i, n / i);
    }
  }
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
long long min(long long a, long long b) {
  if (a < b)
    return a;
  else
    return b;
}
long long po[300005];
long long constants[10];
long long ab[200000];
map<pair<long long, long long>, long long> cd;
long long d, x, y;
void extendedEuclid(long long a, long long b) {
  if (b == 0) {
    d = a;
    x = 1;
    y = 0;
    extendedEuclid(b, a % b);
  } else {
    long long temp = x;
    x = y;
    y = temp - (a / b) * y;
  }
}
long long stringmod(string s, long long m) {
  long long res = 0;
  for (long long i = 0; i < s.length(); i++) {
    res = (res * 10 + (long long)s[i] - '0') % m;
  }
  return res;
}
long long fact[200005];
long long nCr(long long n, long long r) {
  long long ans = fact[n];
  ans = (ans * mod_power(fact[n - r], 1000000007 - 2, 1000000007)) % 1000000007;
  ans %= 1000000007;
  ans %= 1000000007;
  return ans;
}
bool compare(const pair<long long, string> &a,
             const pair<long long, string> &b) {
  if (a.first == b.first)
    return (a.second < b.second);
  else
    return (a.first > b.first);
}
long long min4(long long a, long long b, long long c, long long d) {
  return min(min(a, b), min(c, d));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long freq[10000] = {0};
  for (long long k = 0; k < n; k++) {
    long long a, b;
    cin >> a >> b;
    long long flag = 0;
    if (s[k] == '1') flag = 1;
    for (long long i = 0; i < b; i++) freq[i] += flag;
    for (long long i = b; i < 10000; i++) {
      if ((i - b) % a == 0) flag ^= 1;
      freq[i] += flag;
    }
  }
  long long maxi = 0;
  for (long long i = 0; i < 10000; i++) maxi = max(maxi, freq[i]);
  cout << maxi << endl;
}

### Prompt

In cpp, your task is to solve the following problem:

It is a holiday season, and Koala is decorating his house with cool lights! He owns n lights, all of which flash periodically.

After taking a quick glance at them, Koala realizes that each of his lights can be described with two parameters a_i and b_i. Light with parameters a_i and b_i will toggle (on to off, or off to on) every a_i seconds starting from the b_i-th second. In other words, it will toggle at the moments b_i, b_i + a_i, b_i + 2 ⋅ a_i and so on.

You know for each light whether it's initially on or off and its corresponding parameters a_i and b_i. Koala is wondering what is the maximum number of lights that will ever be on at the same time. So you need to find that out.

<image> Here is a graphic for the first example.

Input

The first line contains a single integer n (1 ≤ n ≤ 100), the number of lights.

The next line contains a string s of n characters. The i-th character is "1", if the i-th lamp is initially on. Otherwise, i-th character is "0".

The i-th of the following n lines contains two integers a_i and b_i (1 ≤ a_i, b_i ≤ 5) — the parameters of the i-th light.

Output

Print a single integer — the maximum number of lights that will ever be on at the same time.

Examples

Input


3
101
3 3
3 2
3 1


Output


2


Input


4
1111
3 4
5 2
3 1
3 2


Output


4


Input


6
011100
5 3
5 5
2 4
3 5
4 2
1 5


Output


6

Note

For first example, the lamps' states are shown in the picture above. The largest number of simultaneously on lamps is 2 (e.g. at the moment 2).

In the second example, all lights are initially on. So the answer is 4.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e18;
bool prime[10009];
void SieveOfEratosthenes(long long n) {
  memset(prime, true, sizeof(prime));
  for (long long p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (long long i = p * p; i <= n; i += p) {
        prime[i] = false;
      }
    }
  }
}
long long power(long long x, long long y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return power(x, y / 2) * power(x, y / 2);
  else
    return x * power(x, y / 2) * power(x, y / 2);
}
long long power1(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      res *= a;
    }
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long mod_power(long long a, long long b, long long m) {
  long long res = 1;
  a %= m;
  while (b) {
    if (b & 1) {
      res = res * a % m;
    }
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
long long printDivisors(long long n) {
  long long count = 0;
  for (long long i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        count++;
      else
        printf("%d %d ", i, n / i);
    }
  }
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
long long min(long long a, long long b) {
  if (a < b)
    return a;
  else
    return b;
}
long long po[300005];
long long constants[10];
long long ab[200000];
map<pair<long long, long long>, long long> cd;
long long d, x, y;
void extendedEuclid(long long a, long long b) {
  if (b == 0) {
    d = a;
    x = 1;
    y = 0;
    extendedEuclid(b, a % b);
  } else {
    long long temp = x;
    x = y;
    y = temp - (a / b) * y;
  }
}
long long stringmod(string s, long long m) {
  long long res = 0;
  for (long long i = 0; i < s.length(); i++) {
    res = (res * 10 + (long long)s[i] - '0') % m;
  }
  return res;
}
long long fact[200005];
long long nCr(long long n, long long r) {
  long long ans = fact[n];
  ans = (ans * mod_power(fact[n - r], 1000000007 - 2, 1000000007)) % 1000000007;
  ans %= 1000000007;
  ans %= 1000000007;
  return ans;
}
bool compare(const pair<long long, string> &a,
             const pair<long long, string> &b) {
  if (a.first == b.first)
    return (a.second < b.second);
  else
    return (a.first > b.first);
}
long long min4(long long a, long long b, long long c, long long d) {
  return min(min(a, b), min(c, d));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long freq[10000] = {0};
  for (long long k = 0; k < n; k++) {
    long long a, b;
    cin >> a >> b;
    long long flag = 0;
    if (s[k] == '1') flag = 1;
    for (long long i = 0; i < b; i++) freq[i] += flag;
    for (long long i = b; i < 10000; i++) {
      if ((i - b) % a == 0) flag ^= 1;
      freq[i] += flag;
    }
  }
  long long maxi = 0;
  for (long long i = 0; i < 10000; i++) maxi = max(maxi, freq[i]);
  cout << maxi << endl;
}

```