import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class CodeForcesTwo {

    public static void main(String[] args) {
        FastReader fastReader = new FastReader();

        int n = fastReader.nextInt();

        char [] charArray= fastReader.next().toCharArray();

        List<Time> list = new ArrayList<Time>();
        int max=0;
        for(int i=0;i<n;i++){
            int start= fastReader.nextInt();
            int stop = fastReader.nextInt();

            max=Math.max(max,start+stop);
            list.add(new Time(start,stop));
        }

        int counter=0;
        for(int j=0;j<n;j++){
            if(charArray[j]=='1'){
                counter+=1;
            }
        }

        if(counter==charArray.length){
            PrintWriter writer = new PrintWriter(System.out);

            writer.println(counter);
            writer.flush();
        }
        else {
            int answer = Integer.MIN_VALUE;
            for (int i = 0; i <= 1000000; i++) {
                int count = 0;

                for (int j = 0; j < n; j++) {
                    Time t = list.get(j);

                    if ((i - t.stop > 0) && (i - t.stop) % t.start == 0) {
                        charArray[j] = charArray[j] == '1' ? '0' : '1';
                    }
                }

                for (int j = 0; j < n; j++) {
                    if (charArray[j] == '1') {
                        count += 1;
                    }
                }
                answer = Math.max(count, answer);
            }
            PrintWriter writer = new PrintWriter(System.out);

            writer.println(answer);
            writer.flush();
        }
    }

    static class Time{
        int start;
        int stop;
        Time(int start,int stop){
            this.start = start;
            this.stop = stop;
        }
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class CodeForcesTwo {

    public static void main(String[] args) {
        FastReader fastReader = new FastReader();

        int n = fastReader.nextInt();

        char [] charArray= fastReader.next().toCharArray();

        List<Time> list = new ArrayList<Time>();
        int max=0;
        for(int i=0;i<n;i++){
            int start= fastReader.nextInt();
            int stop = fastReader.nextInt();

            max=Math.max(max,start+stop);
            list.add(new Time(start,stop));
        }

        int answer=Integer.MIN_VALUE;
        for(int i=0;i<=1000000;i++){
            int count=0;
            for(int j=0;j<n;j++){
                Time t = list.get(j);

                if((i-t.stop>0) && (i-t.stop)%t.start==0){
                    charArray[j]=charArray[j]=='1'?'0':'1';
                }
            }

            for(int j=0;j<n;j++){
                if(charArray[j]=='1'){
                    count+=1;
                }
            }
            answer = Math.max(count, answer);

            PrintWriter writer = new PrintWriter(System.out);

            writer.println(answer);
            writer.flush();
        }
    }

    static class Time{
        int start;
        int stop;
        Time(int start,int stop){
            this.start = start;
            this.stop = stop;
        }
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class CodeForcesTwo {

    public static void main(String[] args) {
        FastReader fastReader = new FastReader();

        int n = fastReader.nextInt();

        char [] charArray= fastReader.next().toCharArray();

        List<Time> list = new ArrayList<Time>();
        int max=0;
        for(int i=0;i<n;i++){
            int start= fastReader.nextInt();
            int stop = fastReader.nextInt();

            max=Math.max(max,start+stop);
            list.add(new Time(start,stop));
        }

        int counter=0;
        for(int j=0;j<n;j++){
            if(charArray[j]=='1'){
                counter+=1;
            }
        }

        if(counter==charArray.length){
            PrintWriter writer = new PrintWriter(System.out);

            writer.println(counter);
            writer.flush();
        }
        else {
            int answer = Integer.MIN_VALUE;
            for (int i = 0; i <= 1000; i++) {
                int count = 0;

                for (int j = 0; j < n; j++) {
                    Time t = list.get(j);

                    if ((t.stop <= i) && (i - t.stop) % t.start == 0) {
                        charArray[j] = charArray[j] == '1' ? '0' : '1';
                    }
                }

                for (int j = 0; j < n; j++) {
                    if (charArray[j] == '1') {
                        count += 1;
                    }
                }
                answer = Math.max(count, answer);
            }
            PrintWriter writer = new PrintWriter(System.out);

            writer.println(answer);
            writer.flush();
        }
    }

    static class Time{
        int start;
        int stop;
        Time(int start,int stop){
            this.start = start;
            this.stop = stop;
        }
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class CodeForcesTwo {

    public static void main(String[] args) {
        FastReader fastReader = new FastReader();

        int n = fastReader.nextInt();

        char [] charArray= fastReader.next().toCharArray();

        List<Time> list = new ArrayList<Time>();
        int max=0;
        for(int i=0;i<n;i++){
            int start= fastReader.nextInt();
            int stop = fastReader.nextInt();

            max=Math.max(max,start+stop);
            list.add(new Time(start,stop));
        }

        int answer=Integer.MIN_VALUE;
        for(int i=0;i<=1000000;i++){
            int count=0;

            for(int j=0;j<n;j++){
                Time t = list.get(j);

                if((i-t.stop>0) && (i-t.stop)%t.start==0){
                    charArray[j]=charArray[j]=='1'?'0':'1';
                }
            }

            for(int j=0;j<n;j++){
                if(charArray[j]=='1'){
                    count+=1;
                }
            }
            answer = Math.max(count, answer);
        }
        PrintWriter writer = new PrintWriter(System.out);

        writer.println(answer);
        writer.flush();
    }

    static class Time{
        int start;
        int stop;
        Time(int start,int stop){
            this.start = start;
            this.stop = stop;
        }
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.util.Scanner;

public class KoalaAndLights {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        String s = sc.next();

        int[][] lightsInterval = new int[n][2];
        for (int i = 0; i < n; ++i) {
            lightsInterval[i][0] = sc.nextInt();
            lightsInterval[i][1] = sc.nextInt();
        }

        char[] temp = s.toCharArray();

        boolean[] lightsState = new boolean[n];

        int len = temp.length;

        for (int i = 0; i < len; ++i) {
            if (temp[i] == '1') {
                lightsState[i] = true;
            } else {
                lightsState[i] = false;
            }
        }

        int[] tempArr = new int[n];

        for (int i = 0; i < n; ++i) {
            tempArr[i] = 2 * lightsInterval[i][0];
        }

        int maxSimTime = lcmOfArr(tempArr);

        int latestStartTime = -1;

        for (int i = 0; i < n; ++i) {
            if (lightsInterval[i][1] > latestStartTime) {
                latestStartTime = lightsInterval[i][1];
            }
        }

        maxSimTime += latestStartTime;

        //System.out.println(maxSimTime);

        int maxLightsOn = 0;

        for (int t = 0; t < maxSimTime; ++t) {

            for (int j = 0; j < n; ++j) {
                if (t <= lightsInterval[j][1]) {
                    continue;
                }

                // Need to toggle
                if (((t - lightsInterval[j][1]) % lightsInterval[j][0]) == 0) {
                    if (lightsState[j]) {
                        lightsState[j] = false;
                    } else {
                        lightsState[j] = true;
                    }
                }
            }

            int countLightsOn = 0;

            for (int j = 0; j < n; ++j) {
                //System.out.println("light " + (j + 1) + ": " + lightsState[j]);
                if (lightsState[j]) {
                    countLightsOn++;
                }
            }

            if (countLightsOn > maxLightsOn) {
                maxLightsOn = countLightsOn;
            }

            /*System.out.println("maxLightsOn: " + maxLightsOn);

            System.out.println();
            System.out.println();*/
        }

        System.out.println(maxLightsOn);
    }

    public static int gcd(int a, int b) {
        if (b == 0) {
            return a;
        }

        return gcd(b, a % b);
    }

    public static int lcmOfArr(int[] arr) {
        int len = arr.length;

        int lcm = arr[0];

        for (int i = 1; i < len; ++i) {
            lcm = (((arr[i]) * lcm) / gcd(arr[i], lcm));
        }

        return lcm;
    }
}


import java.util.Scanner;

public class KoalaAndLights {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        String s = sc.next();

        int[][] lightsInterval = new int[n][2];
        for (int i = 0; i < n; ++i) {
            lightsInterval[i][0] = sc.nextInt();
            lightsInterval[i][1] = sc.nextInt();
        }

        char[] temp = s.toCharArray();

        boolean[] lightsState = new boolean[n];

        int len = temp.length;

        for (int i = 0; i < len; ++i) {
            if (temp[i] == '1') {
                lightsState[i] = true;
            } else {
                lightsState[i] = false;
            }
        }

        int[] tempArr = new int[n];

        for (int i = 0; i < n; ++i) {
            tempArr[i] = 2 * lightsInterval[i][0];
        }

        int maxSimTime = lcmOfArr(tempArr);

        int latestStartTime = -1;

        for (int i = 0; i < n; ++i) {
            if (lightsInterval[i][1] > latestStartTime) {
                latestStartTime = lightsInterval[i][1];
            }
        }

        maxSimTime += latestStartTime;

        System.out.println(maxSimTime);

        int maxLightsOn = 0;

        for (int t = 0; t < maxSimTime; ++t) {

            for (int j = 0; j < n; ++j) {
                if (t <= lightsInterval[j][1]) {
                    continue;
                }

                // Need to toggle
                if (((t - lightsInterval[j][1]) % lightsInterval[j][0]) == 0) {
                    if (lightsState[j]) {
                        lightsState[j] = false;
                    } else {
                        lightsState[j] = true;
                    }
                }
            }

            int countLightsOn = 0;

            for (int j = 0; j < n; ++j) {
                //System.out.println("light " + (j + 1) + ": " + lightsState[j]);
                if (lightsState[j]) {
                    countLightsOn++;
                }
            }

            if (countLightsOn > maxLightsOn) {
                maxLightsOn = countLightsOn;
            }

            /*System.out.println("maxLightsOn: " + maxLightsOn);

            System.out.println();
            System.out.println();*/
        }

        System.out.println(maxLightsOn);
    }

    public static int gcd(int a, int b) {
        if (b == 0) {
            return a;
        }

        return gcd(b, a % b);
    }

    public static int lcmOfArr(int[] arr) {
        int len = arr.length;

        int lcm = arr[0];

        for (int i = 1; i < len; ++i) {
            lcm = (((arr[i]) * lcm) / gcd(arr[i], lcm));
        }

        return lcm;
    }
}


import java.util.Scanner;

public class KoalaAndLights {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        String s = sc.next();

        int[][] lightsInterval = new int[n][2];

        for (int i = 0; i < n; ++i) {
            lightsInterval[i][0] = sc.nextInt();
            lightsInterval[i][1] = sc.nextInt();
        }

        char[] temp = s.toCharArray();

        boolean[] lightsState = new boolean[n];

        int len = temp.length;

        for (int i = 0; i < len; ++i) {
            if (temp[i] == '1') {
                lightsState[i] = true;
            } else {
                lightsState[i] = false;
            }
        }

        int[] tempArr = new int[n];

        for (int i = 0; i < n; ++i) {
            tempArr[i] = 2 * lightsInterval[i][0];
        }

        int maxSimTime = lcmOfArr(tempArr);

        int latestStartTime = Integer.MIN_VALUE;

        for (int i = 0; i < n; ++i) {
            if (lightsInterval[i][1] > latestStartTime) {
                latestStartTime = lightsInterval[i][1];
            }
        }

        maxSimTime += latestStartTime;

        int maxLightsOn = 0;

        for (int t = 0; t <= maxSimTime; ++t) {

            for (int j = 0; j < n; ++j) {
                if (t < lightsInterval[j][1]) {
                    continue;
                }

                // Need to toggle
                if (((t - lightsInterval[j][1]) % lightsInterval[j][0]) == 0) {
                    if (lightsState[j]) {
                        lightsState[j] = false;
                    } else {
                        lightsState[j] = true;
                    }
                }
            }

            int countLightsOn = 0;

            for (int j = 0; j < n; ++j) {
                if (lightsState[j]) {
                    countLightsOn++;
                }
            }

            if (countLightsOn > maxLightsOn) {
                maxLightsOn = countLightsOn;
            }
        }

        System.out.println(maxLightsOn);
    }

    public static int gcd(int a, int b) {
        if (b == 0) {
            return a;
        }

        return gcd(b, a % b);
    }

    public static int lcmOfArr(int[] arr) {
        int len = arr.length;

        int lcm = arr[0];

        for (int i = 1; i < len; ++i) {
            lcm = (((arr[i]) * lcm) / gcd(arr[i], lcm));
        }

        return lcm;
    }
}


import java.util.Scanner;

public class KoalaAndLights {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        String s = sc.next();

        int[][] lightsInterval = new int[n][2];
        for (int i = 0; i < n; ++i) {
            lightsInterval[i][0] = sc.nextInt();
            lightsInterval[i][1] = sc.nextInt();
        }

        char[] temp = s.toCharArray();

        boolean[] lightsState = new boolean[n];

        int len = temp.length;

        for (int i = 0; i < len; ++i) {
            if (temp[i] == '1') {
                lightsState[i] = true;
            } else {
                lightsState[i] = false;
            }
        }

        int[] tempArr = new int[n];

        for (int i = 0; i < n; ++i) {
            tempArr[i] = 2 * lightsInterval[i][0];
        }

        int maxSimTime = lcmOfArr(tempArr);

        int latestStartTime = Integer.MIN_VALUE;

        for (int i = 0; i < n; ++i) {
            if (lightsInterval[i][1] > latestStartTime) {
                latestStartTime = lightsInterval[i][1];
            }
        }

        maxSimTime += latestStartTime;

        //System.out.println(maxSimTime);

        int maxLightsOn = 0;

        for (int t = 0; t <= maxSimTime; ++t) {

            for (int j = 0; j < n; ++j) {
                if (t < lightsInterval[j][1]) {
                    continue;
                }

                //System.out.println("t - lightsInterval[j][1] = " + (t - lightsInterval[j][1]));
                // Need to toggle
                if (((t - lightsInterval[j][1]) % lightsInterval[j][0]) == 0) {
                    if (lightsState[j]) {
                        lightsState[j] = false;
                    } else {
                        lightsState[j] = true;
                    }
                }
            }

            int countLightsOn = 0;

            for (int j = 0; j < n; ++j) {
                //System.out.println("light " + (j + 1) + ": " + lightsState[j]);
                if (lightsState[j]) {
                    countLightsOn++;
                }
            }

            if (countLightsOn > maxLightsOn) {
                maxLightsOn = countLightsOn;
            }

            /*System.out.println("maxLightsOn: " + maxLightsOn);

            System.out.println();
            System.out.println();*/
        }

        System.out.println(maxLightsOn);
    }

    public static int gcd(int a, int b) {
        if (b == 0) {
            return a;
        }

        return gcd(b, a % b);
    }

    public static int lcmOfArr(int[] arr) {
        int len = arr.length;

        int lcm = arr[0];

        for (int i = 1; i < len; ++i) {
            lcm = (((arr[i]) * lcm) / gcd(arr[i], lcm));
        }

        return lcm;
    }
}


import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class B {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String initStatusStr = null;
		while (initStatusStr == null || initStatusStr.isEmpty()) initStatusStr = sc.nextLine();
		int[] initDelay = new int[n], delay = new int[n];
		for (int i = 0; i < n; i++) {
			delay[i] = sc.nextInt();
			initDelay[i] = sc.nextInt();
		}
		sc.close();

		char[] status = initStatusStr.toCharArray();
//		Set<String> allStatus = new HashSet<>();
		int max = 0;
		for (int t = 0; t < 10000; ++t) {
			for (int i = 0; i < n; i++) {
				if (t >= initDelay[i] && (t - initDelay[i]) % delay[i] == 0)
					status[i] = status[i] == '1' ? '0' : '1';
			}
			int cnt = 0;
			for (char ch : status) if (ch == '1') cnt++;
			max = Math.max(max, cnt);
//			System.out.println(t + " " + cnt + " " + new String(status));
		}

		System.out.println(max);
	}

}


import java.io.*;
import java.util.*;
public class vk18
{
    public static void main(String[]st) throws Exception
    {
    	Scanner scan=new Scanner(System.in);
        //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //String s[];
        int i;
        int n;
        String na;
        n=scan.nextInt();
        na=scan.next();
        int a[][]=new int[n][2];
        for(i=0;i<n;i++)  { a[i][0]=scan.nextInt(); a[i][1]=scan.nextInt(); }
        int ans=0,max=Integer.MIN_VALUE,temp=0,t;
        for(t=0;t<1000;t++)
        {
        	ans=0;
        	for(i=0;i<n;i++)
        	{
        		if(t<a[i][1]){ if(na.charAt(i)=='1') ans++; }
        		else { temp=(t-a[i][1])/a[i][0];
        				if(na.charAt(i)=='1' && temp%2==1 || na.charAt(i)=='0' && temp%2==0) ans++;
        				}
        	}
        	max=Math.max(max,ans);
        }
        max=Math.max(max,ans);
        System.out.println(max);
    }
}


import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new PrintStream(System.out));
        int n=Integer.parseInt(f.readLine());
        String str=f.readLine();
        char[]arr2=str.toCharArray();
        int[]arr=new int[n];
        PriorityQueue<pair>q=new PriorityQueue<>();
        for(int i=0;i<n;i++){
            StringTokenizer st=new StringTokenizer(f.readLine());
            int a=Integer.parseInt(st.nextToken());
            int b=Integer.parseInt(st.nextToken());
            q.add(new pair(b,a,i));
        }
        int on=0;
        int ans=0;
        for(int i=0;i<str.length();i++){
            if(str.charAt(i)=='1')on++;
        }
        ans=on;
        for(int i=0;i<100000;i++){
            pair a=q.poll();
            if (arr2[a.idx] == '0') {
                arr2[a.idx]='1';
                on++;
            }
            else{
                arr2[a.idx]='0';
                on--;
            }
            a.num+=a.next;
            q.add(a);

            while(q.peek().num==a.num-a.next){
                a=q.poll();
                if (arr2[a.idx] == '0') {
                    arr2[a.idx]='1';
                    on++;
                }
                else{
                    arr2[a.idx]='0';
                    on--;
                }
                a.num+=a.next;
                q.add(a);
            }

            ans=Math.max(ans,on);
        }
        System.out.print(ans);
        f.close();
        out.close();
    }
}
class pair implements Comparable <pair>{
    int num;
    int next;
    int idx;
    public int compareTo(pair other){
        return num- other.num;
    }

    pair(int a, int b,int c)
    {
        num=a;
        next=b;idx=c;
    }
}


import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new PrintStream(System.out));
        int n=Integer.parseInt(f.readLine());
        String str=f.readLine();
        char[]arr2=str.toCharArray();
        int[]arr=new int[n];
        PriorityQueue<pair>q=new PriorityQueue<>();
        for(int i=0;i<n;i++){
            StringTokenizer st=new StringTokenizer(f.readLine());
            int a=Integer.parseInt(st.nextToken());
            int b=Integer.parseInt(st.nextToken());
            q.add(new pair(a,b,i));
        }
        int on=0;
        int ans=0;
        for(int i=0;i<str.length();i++){
            if(str.charAt(i)=='1')on++;
        }
        for(int i=0;i<10000000;i++){
            pair a=q.poll();
            if (arr2[a.idx] == '0') {
                arr2[a.idx]='1';
                on++;
            }
            else{
                arr2[a.idx]='0';
                on--;
            }
            ans=Math.max(ans,on);
            a.num+=a.next;
            q.add(a);
        }
        System.out.print(ans);
        f.close();
        out.close();
    }
}
class pair implements Comparable <pair>{
    int num;
    int next;
    int idx;
    public int compareTo(pair other){
        return num- other.num;
    }

    pair(int a, int b,int c)
    {
        num=a;
        next=b;idx=c;
    }
}


import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new PrintStream(System.out));
        int n=Integer.parseInt(f.readLine());
        String str=f.readLine();
        char[]arr2=str.toCharArray();
        int[]arr=new int[n];
        PriorityQueue<pair>q=new PriorityQueue<>();
        for(int i=0;i<n;i++){
            StringTokenizer st=new StringTokenizer(f.readLine());
            int a=Integer.parseInt(st.nextToken());
            int b=Integer.parseInt(st.nextToken());
            q.add(new pair(b,a,i));
        }
        int on=0;
        int ans=0;
        for(int i=0;i<str.length();i++){
            if(str.charAt(i)=='1')on++;
        }
        ans=on;
        for(int i=0;i<1000000;i++){
            pair a=q.poll();
            if (arr2[a.idx] == '0') {
                arr2[a.idx]='1';
                on++;
            }
            else{
                arr2[a.idx]='0';
                on--;
            }
            a.num+=a.next;
            q.add(a);

            while(q.peek().num==a.num-a.next){
                a=q.poll();
                if (arr2[a.idx] == '0') {
                    arr2[a.idx]='1';
                    on++;
                }
                else{
                    arr2[a.idx]='0';
                    on--;
                }
                a.num+=a.next;
                q.add(a);
            }

            ans=Math.max(ans,on);
        }
        System.out.print(ans);
        f.close();
        out.close();
    }
}
class pair implements Comparable <pair>{
    int num;
    int next;
    int idx;
    public int compareTo(pair other){
        return num- other.num;
    }

    pair(int a, int b,int c)
    {
        num=a;
        next=b;idx=c;
    }
}


import java.io.*;
import java.util.*;
public class koala
{
    public static void main(String args[])
    {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        String s=in.next();
        int flag[]=new int[n];
        int a[]=new int[n];
        int b[]=new int[n];
        int c[]=new int[n];
        for(int i=0;i<n;i++)
        {
            a[i]=in.nextInt();
            b[i]=in.nextInt();
        }
        int curtime=0;
        for(int i=0;i<n;i++)
        {
            flag[i]=s.charAt(i)-'0';
            c[i]=0;
        }
        int count=0;
            int max=0;
            while(curtime<200)
            {
                count=0;
                for(int i=0;i<n;i++)
                {
                if(curtime==b[i]+c[i]*a[i])
                {
                    if(flag[i]==0)
                     flag[i]=1;
                    else if(flag[i]==1)
                     flag[i]=0;
                    c[i]++;
                }
               }
               for(int i=0;i<n;i++)
               {
                 count+=flag[i];
               }

               if(count>max)
                 max=count;
                curtime++;
        }
        System.out.println(max);
    }
}


import java.io.*;
import java.util.*;

public class Main {
    private final static long mod = 1000000007;

    private final static int MAXN = 100001;

    private static long power(long x, long y, long m) {
        long temp;
        if (y == 0)
            return 1;
        temp = power(x, y / 2, m);
        temp = (temp * temp) % m;
        if (y % 2 == 0)
            return temp;
        else
            return ((x % m) * temp) % m;
    }

    private static long power(long x, long y) {
        return power(x, y, mod);
    }

    private static long gcd(long a, long b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    static int nextPowerOf2(int a) {
        return 1 << nextLog2(a);
    }

    static int nextLog2(int a) {
        return (a == 0 ? 0 : 32 - Integer.numberOfLeadingZeros(a - 1));
    }

    private static long modInverse(long a, long m) {
        long m0 = m;
        long y = 0, x = 1;
        if (m == 1)
            return 0;
        while (a > 1) {
            long q = a / m;
            long t = m;
            m = a % m;
            a = t;
            t = y;
            y = x - q * y;
            x = t;
        }
        if (x < 0)
            x += m0;
        return x;
    }

    private static int[] getLogArr(int n) {
        int arr[] = new int[n + 1];
        for (int i = 1; i < n + 1; i++) {
            arr[i] = (int) (Math.log(i) / Math.log(2) + 1e-10);
        }
        return arr;
    }

    private static int log[] = getLogArr(MAXN);

    private static int getLRMax(int st[][], int L, int R) {
        int j = log[R - L + 1];
        return Math.max(st[L][j], st[R - (1 << j) + 1][j]);
    }

    private static int[][] getSparseTable(int array[]) {
        int k = log[MAXN] + 1;
        int st[][] = new int[MAXN][k + 1];

        for (int i = 0; i < array.length; i++)
            st[i][0] = array[i];

        for (int j = 1; j <= k; j++) {
            for (int i = 0; i + (1 << j) <= array.length; i++) {
                st[i][j] = Math.max(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
            }
        }
        return st;
    }

    static class Subset {
        int parent;
        int rank;

        @Override
        public String toString() {
            return "" + parent;
        }
    }

    static int find(Subset[] Subsets, int i) {
        if (Subsets[i].parent != i)
            Subsets[i].parent = find(Subsets, Subsets[i].parent);
        return Subsets[i].parent;
    }

    static void union(Subset[] Subsets, int x, int y) {
        int xroot = find(Subsets, x);
        int yroot = find(Subsets, y);

        if (Subsets[xroot].rank < Subsets[yroot].rank)
            Subsets[xroot].parent = yroot;
        else if (Subsets[yroot].rank < Subsets[xroot].rank)
            Subsets[yroot].parent = xroot;
        else {
            Subsets[xroot].parent = yroot;
            Subsets[yroot].rank++;
        }
    }

    private static int maxx(Integer... a) {
        return Collections.max(Arrays.asList(a));
    }

    private static class Pair<T, U> {
        T a;
        U b;

        public Pair(T a, U b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Pair pair = (Pair) o;
            return a.equals(pair.a) &&
                    b.equals(pair.b);
        }

        @Override
        public int hashCode() {
            return Objects.hash(a, b);
        }

        @Override
        public String toString() {
            return "(" + a +
                    "," + b +
                    ')';
        }
    }

    public static void main(String[] args) throws Exception {
        try (FastReader in = new FastReader();
             FastWriter out = new FastWriter()) {
            int t, i, j, n, k, l, r, m, c, p, q, ti, tidx;
            long x, y, z;

            //for (t = in.nextInt(), tidx = 1; tidx <= t; tidx++)
            {
                //out.print(String.format("Case #%d: ", tidx));
                n=in.nextInt();
                String s=in.next();
                int a[]=new int[n];
                int b[]=new int[n];
                for(i=0;i<n;i++){
                    a[i]=in.nextInt();
                    b[i]=in.nextInt();
                }
                int lights[][]=new int[n][126];
                int lc[]=new int[126];
                m=0;
                for(i=0;i<n;i++){
                    if(s.charAt(i)=='1'){
                        lights[i][0]=1;
                        lc[0]++;
                    }
                    int toggle[]=new int[126];
                    for(j=b[i];j<126;j+=a[i]){
                        toggle[j]=1;
                    }
                    for(j=1;j<126;j++){
                        lights[i][j]=(lights[i][j-1]+toggle[j])%2;
                        if(lights[i][j]==1)lc[j]++;
                    }
                }
                out.println(Arrays.stream(lc).max().getAsInt());
            }
            out.commit();
        }
    }

    static class FastReader implements Closeable {
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer st;

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int[] nextIntArr(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        double[] nextDoubleArr(int n) {
            double[] arr = new double[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextDouble();
            }
            return arr;
        }

        long[] nextLongArr(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

        String[] nextStrArr(int n) {
            String[] arr = new String[n];
            for (int i = 0; i < n; i++) {
                arr[i] = next();
            }
            return arr;
        }

        int[][] nextIntArr2(int n, int m) {
            int[][] arr = new int[n][m];
            for (int i = 0; i < n; i++) {
                arr[i] = nextIntArr(m);
            }
            return arr;
        }

        long[][] nextLongArr2(int n, int m) {
            long[][] arr = new long[n][m];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLongArr(m);
            }
            return arr;
        }

        @Override
        public void close() throws IOException {
            br.close();
        }
    }

    static class FastWriter implements Closeable {
        BufferedWriter bw;
        StringBuilder sb = new StringBuilder();
        List<String> list = new ArrayList<>();
        Set<String> set = new HashSet<>();

        FastWriter() {
            bw = new BufferedWriter(new OutputStreamWriter(System.out));
        }

        <T> void commit() throws IOException {
            bw.write(sb.toString());
            bw.flush();
            sb = new StringBuilder();
        }

        <T> void print(T obj) {
            sb.append(obj.toString());
        }

        void println() throws IOException {
            print("\n");
        }

        <T> void println(T obj) throws IOException {
            print(obj.toString() + "\n");
        }

        <T> void printArrLn(T[] arr) throws IOException {
            for (int i = 0; i < arr.length - 1; i++) {
                print(arr[i] + " ");
            }
            println(arr[arr.length - 1]);
        }

        <T> void printArr2(T[][] arr) throws IOException {
            for (int j = 0; j < arr.length; j++) {
                for (int i = 0; i < arr[j].length - 1; i++) {
                    print(arr[j][i] + " ");
                }
                println(arr[j][arr.length - 1]);
            }
        }

        <T> void printColl(Collection<T> coll) throws IOException {
            for (T e : coll) {
                print(e + " ");
            }
            println();
        }

        void printCharN(char c, int n) throws IOException {
            for (int i = 0; i < n; i++) {
                print(c);
            }
        }

        void printIntArr2(int[][] arr) throws IOException {
            for (int j = 0; j < arr.length; j++) {
                for (int i = 0; i < arr[j].length - 1; i++) {
                    print(arr[j][i] + " ");
                }
                println(arr[j][arr.length - 1]);
            }
        }

        @Override
        public void close() throws IOException {
            bw.close();
        }
    }

}


import java.io.*;
import java.util.*;

public class Main {
    private final static long mod = 1000000007;

    private final static int MAXN = 100001;

    private static long power(long x, long y, long m) {
        long temp;
        if (y == 0)
            return 1;
        temp = power(x, y / 2, m);
        temp = (temp * temp) % m;
        if (y % 2 == 0)
            return temp;
        else
            return ((x % m) * temp) % m;
    }

    private static long power(long x, long y) {
        return power(x, y, mod);
    }

    private static long gcd(long a, long b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    static int nextPowerOf2(int a) {
        return 1 << nextLog2(a);
    }

    static int nextLog2(int a) {
        return (a == 0 ? 0 : 32 - Integer.numberOfLeadingZeros(a - 1));
    }

    private static long modInverse(long a, long m) {
        long m0 = m;
        long y = 0, x = 1;
        if (m == 1)
            return 0;
        while (a > 1) {
            long q = a / m;
            long t = m;
            m = a % m;
            a = t;
            t = y;
            y = x - q * y;
            x = t;
        }
        if (x < 0)
            x += m0;
        return x;
    }

    private static int[] getLogArr(int n) {
        int arr[] = new int[n + 1];
        for (int i = 1; i < n + 1; i++) {
            arr[i] = (int) (Math.log(i) / Math.log(2) + 1e-10);
        }
        return arr;
    }

    private static int log[] = getLogArr(MAXN);

    private static int getLRMax(int st[][], int L, int R) {
        int j = log[R - L + 1];
        return Math.max(st[L][j], st[R - (1 << j) + 1][j]);
    }

    private static int[][] getSparseTable(int array[]) {
        int k = log[MAXN] + 1;
        int st[][] = new int[MAXN][k + 1];

        for (int i = 0; i < array.length; i++)
            st[i][0] = array[i];

        for (int j = 1; j <= k; j++) {
            for (int i = 0; i + (1 << j) <= array.length; i++) {
                st[i][j] = Math.max(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
            }
        }
        return st;
    }

    static class Subset {
        int parent;
        int rank;

        @Override
        public String toString() {
            return "" + parent;
        }
    }

    static int find(Subset[] Subsets, int i) {
        if (Subsets[i].parent != i)
            Subsets[i].parent = find(Subsets, Subsets[i].parent);
        return Subsets[i].parent;
    }

    static void union(Subset[] Subsets, int x, int y) {
        int xroot = find(Subsets, x);
        int yroot = find(Subsets, y);

        if (Subsets[xroot].rank < Subsets[yroot].rank)
            Subsets[xroot].parent = yroot;
        else if (Subsets[yroot].rank < Subsets[xroot].rank)
            Subsets[yroot].parent = xroot;
        else {
            Subsets[xroot].parent = yroot;
            Subsets[yroot].rank++;
        }
    }

    private static int maxx(Integer... a) {
        return Collections.max(Arrays.asList(a));
    }

    private static class Pair<T, U> {
        T a;
        U b;

        public Pair(T a, U b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Pair pair = (Pair) o;
            return a.equals(pair.a) &&
                    b.equals(pair.b);
        }

        @Override
        public int hashCode() {
            return Objects.hash(a, b);
        }

        @Override
        public String toString() {
            return "(" + a +
                    "," + b +
                    ')';
        }
    }

    public static void main(String[] args) throws Exception {
        try (FastReader in = new FastReader();
             FastWriter out = new FastWriter()) {
            int t, i, j, n, k, l, r, m, c, p, q, ti, tidx;
            long x, y, z;

            //for (t = in.nextInt(), tidx = 1; tidx <= t; tidx++)
            {
                //out.print(String.format("Case #%d: ", tidx));
                n=in.nextInt();
                String s=in.next();
                int a[]=new int[n];
                int b[]=new int[n];
                for(i=0;i<n;i++){
                    a[i]=in.nextInt();
                    b[i]=in.nextInt();
                }
                int lights[][]=new int[n][126];
                int lc[]=new int[126];
                m=0;
                for(i=0;i<n;i++){
                    if(s.charAt(i)=='1'){
                        lc[0]++;
                    }
                    for(j=1;j<126;j++){
                        if(s.charAt(i)=='1') {
                            if (j - b[i] >= 0 && ((j - b[i]) / a[i]) % 2 == 0) {
                                lc[j]++;
                            }
                        }
                        else {
                            if (j - b[i] >= 0 && ((j - b[i]) / a[i]) % 2 == 1) {
                                lc[j]++;
                            }
                        }
                    }
                }

                out.println(Arrays.stream(lc).max().getAsInt());
            }
            out.commit();
        }
    }

    static class FastReader implements Closeable {
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer st;

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int[] nextIntArr(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        double[] nextDoubleArr(int n) {
            double[] arr = new double[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextDouble();
            }
            return arr;
        }

        long[] nextLongArr(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

        String[] nextStrArr(int n) {
            String[] arr = new String[n];
            for (int i = 0; i < n; i++) {
                arr[i] = next();
            }
            return arr;
        }

        int[][] nextIntArr2(int n, int m) {
            int[][] arr = new int[n][m];
            for (int i = 0; i < n; i++) {
                arr[i] = nextIntArr(m);
            }
            return arr;
        }

        long[][] nextLongArr2(int n, int m) {
            long[][] arr = new long[n][m];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLongArr(m);
            }
            return arr;
        }

        @Override
        public void close() throws IOException {
            br.close();
        }
    }

    static class FastWriter implements Closeable {
        BufferedWriter bw;
        StringBuilder sb = new StringBuilder();
        List<String> list = new ArrayList<>();
        Set<String> set = new HashSet<>();

        FastWriter() {
            bw = new BufferedWriter(new OutputStreamWriter(System.out));
        }

        <T> void commit() throws IOException {
            bw.write(sb.toString());
            bw.flush();
            sb = new StringBuilder();
        }

        <T> void print(T obj) {
            sb.append(obj.toString());
        }

        void println() throws IOException {
            print("\n");
        }

        <T> void println(T obj) throws IOException {
            print(obj.toString() + "\n");
        }

        <T> void printArrLn(T[] arr) throws IOException {
            for (int i = 0; i < arr.length - 1; i++) {
                print(arr[i] + " ");
            }
            println(arr[arr.length - 1]);
        }

        <T> void printArr2(T[][] arr) throws IOException {
            for (int j = 0; j < arr.length; j++) {
                for (int i = 0; i < arr[j].length - 1; i++) {
                    print(arr[j][i] + " ");
                }
                println(arr[j][arr.length - 1]);
            }
        }

        <T> void printColl(Collection<T> coll) throws IOException {
            for (T e : coll) {
                print(e + " ");
            }
            println();
        }

        void printCharN(char c, int n) throws IOException {
            for (int i = 0; i < n; i++) {
                print(c);
            }
        }

        void printIntArr2(int[][] arr) throws IOException {
            for (int j = 0; j < arr.length; j++) {
                for (int i = 0; i < arr[j].length - 1; i++) {
                    print(arr[j][i] + " ");
                }
                println(arr[j][arr.length - 1]);
            }
        }

        @Override
        public void close() throws IOException {
            bw.close();
        }
    }

}


import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class Koala_and_lights {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int n = in.nextInt();
        int[] a = new int[n];
        char[] s = in.next().toCharArray();

        int[][] arr = new int[105][1010];

        for(int i = 0; i < s.length; i++){
            if(s[i] == '1')arr[i][0] = 1;
            else arr[i][0] = 2;
        }

        for(int i = 0; i < n;i++){
            int x = in.nextInt();
            int y = in.nextInt();

            if(arr[i][0] == 1){
                arr[i][y] = 2;
            }
            else arr[i][y] = 1;

            for(int j = y+x; j < 1010; j += x){
                if(arr[i][j-x] == 1){
                    arr[i][j] = 2;
                }
                else arr[i][j] = 1;
            }

            for(int j = 1; j < 1010; j++) {
                if(arr[i][j] == 0){
                    arr[i][j] = arr[i][j-1];
                }
            }
        }

        int mx = -1;

        for(int j = 0; j < 1010; j++){
            int c = 0;
            for(int i = 0; i < 105; i++){
                if(arr[i][j] == 1)c++;
            }
            mx = Math.max(mx, c);
        }

        pw.println(mx);
        pw.close();
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BKoalaAndLights solver = new BKoalaAndLights();
        solver.solve(1, in, out);
        out.close();
    }

    static class BKoalaAndLights {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int MAX = 10000;
            int n = in.nextInt();
            char[] s = in.nextString().toCharArray();
            int max = 0;
            int[] count = new int[MAX];
            for (int i = 0; i < n; ++i) {
                int cur = s[i] - '0';
                int a = in.nextInt();
                int b = in.nextInt();

                for (int j = 0; j < MAX; ++j) {
                    count[j] += cur;
                    max = Math.max(max, count[j]);
                    if (j == b) {
                        cur ^= 1;
                        b += a;
                    }
                }
            }
            out.println(max);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int pnumChars;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        private int pread() {
            if (pnumChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= pnumChars) {
                curChar = 0;
                try {
                    pnumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (pnumChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = pread();
            while (isSpaceChar(c))
                c = pread();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = pread();
            }
            int res = 0;
            do {
                if (c == ',') {
                    c = pread();
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = pread();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextString() {
            int c = pread();
            while (isSpaceChar(c))
                c = pread();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = pread();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.OptionalInt;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BKoalaAndLights solver = new BKoalaAndLights();
        solver.solve(1, in, out);
        out.close();
    }

    static class BKoalaAndLights {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int MAX = 10000;
            int n = in.nextInt();
            char[] s = in.nextString().toCharArray();

            int[] count = new int[MAX];
            for (int i = 0; i < n; ++i) {
                int cur = s[i] - '0';
                int a = in.nextInt();
                int b = in.nextInt();

                for (int j = 0; j < MAX; ++j) {
                    count[j] += cur;
                    if (j == b) {
                        cur ^= 1;
                        b += a;
                    }
                }
            }
            out.println(Arrays.stream(count).max().getAsInt());
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int pnumChars;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        private int pread() {
            if (pnumChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= pnumChars) {
                curChar = 0;
                try {
                    pnumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (pnumChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = pread();
            while (isSpaceChar(c))
                c = pread();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = pread();
            }
            int res = 0;
            do {
                if (c == ',') {
                    c = pread();
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = pread();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextString() {
            int c = pread();
            while (isSpaceChar(c))
                c = pread();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = pread();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}


import java.io.*;
import java.util.*;

public class B implements Runnable {
	FastReader scn;
	PrintWriter out;
	String INPUT = "";

	void solve() {
		int n = scn.nextInt();
		int[] arr = new int[1001];
		char[] s = scn.next().toCharArray();
		for(int i = 0; i < n; i++) {
			int a = scn.nextInt(), b = scn.nextInt();
			for(int j = 0; j < b; j++) {
				arr[j] += s[i] - '0';
			}
			if(s[i] == '0') {
				b += a;
			}
			for(int j = b; j < arr.length; j++) {
				int x = (j - b) / a;
				arr[j] += (x % 2);
			}
		}

		int ans = 0;
		for(int a : arr) {
			ans = Math.max(ans, a);
		}
		out.println(ans);
	}

	public void run() {
		long time = System.currentTimeMillis();
		boolean oj = System.getProperty("ONLINE_JUDGE") != null;
		out = new PrintWriter(System.out);
		scn = new FastReader(oj);
		solve();
		out.flush();
		if (!oj) {
			System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" }));
		}
	}

	public static void main(String[] args) {
		new Thread(null, new B(), "Main", 1 << 26).start();
	}

	class FastReader {
		InputStream is;

		public FastReader(boolean onlineJudge) {
			is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		}

		byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

		int readByte() {
			if (lenbuf == -1)
				throw new InputMismatchException();
			if (ptrbuf >= lenbuf) {
				ptrbuf = 0;
				try {
					lenbuf = is.read(inbuf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return -1;
			}
			return inbuf[ptrbuf++];
		}

		boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b))
				;
			return b;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		char nextChar() {
			return (char) skip();
		}

		String next() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		String nextLine() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while ((!isSpaceChar(b) || b == ' ')) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		char[] next(int n) {
			char[] buf = new char[n];
			int b = skip(), p = 0;
			while (p < n && !(isSpaceChar(b))) {
				buf[p++] = (char) b;
				b = readByte();
			}
			return n == p ? buf : Arrays.copyOf(buf, p);
		}

		int nextInt() {
			int num = 0, b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		long nextLong() {
			long num = 0;
			int b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		char[][] nextMatrix(int n, int m) {
			char[][] map = new char[n][];
			for (int i = 0; i < n; i++)
				map[i] = next(m);
			return map;
		}

		int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		int[][] next2DInt(int n, int m) {
			int[][] arr = new int[n][];
			for (int i = 0; i < n; i++) {
				arr[i] = nextIntArray(m);
			}
			return arr;
		}

		long[][] next2DLong(int n, int m) {
			long[][] arr = new long[n][];
			for (int i = 0; i < n; i++) {
				arr[i] = nextLongArray(m);
			}
			return arr;
		}

		int[] shuffle(int[] arr) {
			Random r = new Random();
			for (int i = 1, j; i < arr.length; i++) {
				j = r.nextInt(i);
				int c = arr[i];
				arr[i] = arr[j];
				arr[j] = c;
			}
			return arr;
		}

		long[] shuffle(long[] arr) {
			Random r = new Random();
			for (int i = 1, j; i < arr.length; i++) {
				j = r.nextInt(i);
				long c = arr[i];
				arr[i] = arr[j];
				arr[j] = c;
			}
			return arr;
		}

		int[] uniq(int[] arr) {
			arr = scn.shuffle(arr);
			Arrays.sort(arr);
			int[] rv = new int[arr.length];
			int pos = 0;
			rv[pos++] = arr[0];
			for (int i = 1; i < arr.length; i++) {
				if (arr[i] != arr[i - 1]) {
					rv[pos++] = arr[i];
				}
			}
			return Arrays.copyOf(rv, pos);
		}

		long[] uniq(long[] arr) {
			arr = scn.shuffle(arr);
			Arrays.sort(arr);
			long[] rv = new long[arr.length];
			int pos = 0;
			rv[pos++] = arr[0];
			for (int i = 1; i < arr.length; i++) {
				if (arr[i] != arr[i - 1]) {
					rv[pos++] = arr[i];
				}
			}
			return Arrays.copyOf(rv, pos);
		}

		int[] reverse(int[] arr) {
			int l = 0, r = arr.length - 1;
			while (l < r) {
				arr[l] = arr[l] ^ arr[r];
				arr[r] = arr[l] ^ arr[r];
				arr[l] = arr[l] ^ arr[r];
				l++;
				r--;
			}
			return arr;
		}

		long[] reverse(long[] arr) {
			int l = 0, r = arr.length - 1;
			while (l < r) {
				arr[l] = arr[l] ^ arr[r];
				arr[r] = arr[l] ^ arr[r];
				arr[l] = arr[l] ^ arr[r];
				l++;
				r--;
			}
			return arr;
		}

		int[] compress(int[] arr) {
			int n = arr.length;
			int[] rv = Arrays.copyOf(arr, n);
			rv = uniq(rv);
			for (int i = 0; i < n; i++) {
				arr[i] = Arrays.binarySearch(rv, arr[i]);
			}
			return arr;
		}

		long[] compress(long[] arr) {
			int n = arr.length;
			long[] rv = Arrays.copyOf(arr, n);
			rv = uniq(rv);
			for (int i = 0; i < n; i++) {
				arr[i] = Arrays.binarySearch(rv, arr[i]);
			}
			return arr;
		}
	}
}


import java.io.*;
import java.util.*;

public class B implements Runnable {
	FastReader scn;
	PrintWriter out;
	String INPUT = "";

	void solve() {
		int n = scn.nextInt();
		int[] arr = new int[1001];
		char[] s = scn.next().toCharArray();
		for(int i = 0; i < n; i++) {
			int a = scn.nextInt(), b = scn.nextInt();
			if(s[i] == '0') {
				b += a;
			}
			for(int j = 0; j < b; j++) {
				arr[j] += s[i] - '0';
			}
			for(int j = b; j < arr.length; j++) {
				int x = (j - b) / a;
				arr[j] += 1 ^ (x % 2);
			}
		}

		int ans = 0;
		for(int a : arr) {
			ans = Math.max(ans, a);
		}
		out.println(ans);
	}

	public void run() {
		long time = System.currentTimeMillis();
		boolean oj = System.getProperty("ONLINE_JUDGE") != null;
		out = new PrintWriter(System.out);
		scn = new FastReader(oj);
		solve();
		out.flush();
		if (!oj) {
			System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" }));
		}
	}

	public static void main(String[] args) {
		new Thread(null, new B(), "Main", 1 << 26).start();
	}

	class FastReader {
		InputStream is;

		public FastReader(boolean onlineJudge) {
			is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		}

		byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

		int readByte() {
			if (lenbuf == -1)
				throw new InputMismatchException();
			if (ptrbuf >= lenbuf) {
				ptrbuf = 0;
				try {
					lenbuf = is.read(inbuf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return -1;
			}
			return inbuf[ptrbuf++];
		}

		boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b))
				;
			return b;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		char nextChar() {
			return (char) skip();
		}

		String next() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		String nextLine() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while ((!isSpaceChar(b) || b == ' ')) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		char[] next(int n) {
			char[] buf = new char[n];
			int b = skip(), p = 0;
			while (p < n && !(isSpaceChar(b))) {
				buf[p++] = (char) b;
				b = readByte();
			}
			return n == p ? buf : Arrays.copyOf(buf, p);
		}

		int nextInt() {
			int num = 0, b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		long nextLong() {
			long num = 0;
			int b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		char[][] nextMatrix(int n, int m) {
			char[][] map = new char[n][];
			for (int i = 0; i < n; i++)
				map[i] = next(m);
			return map;
		}

		int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		int[][] next2DInt(int n, int m) {
			int[][] arr = new int[n][];
			for (int i = 0; i < n; i++) {
				arr[i] = nextIntArray(m);
			}
			return arr;
		}

		long[][] next2DLong(int n, int m) {
			long[][] arr = new long[n][];
			for (int i = 0; i < n; i++) {
				arr[i] = nextLongArray(m);
			}
			return arr;
		}

		int[] shuffle(int[] arr) {
			Random r = new Random();
			for (int i = 1, j; i < arr.length; i++) {
				j = r.nextInt(i);
				int c = arr[i];
				arr[i] = arr[j];
				arr[j] = c;
			}
			return arr;
		}

		long[] shuffle(long[] arr) {
			Random r = new Random();
			for (int i = 1, j; i < arr.length; i++) {
				j = r.nextInt(i);
				long c = arr[i];
				arr[i] = arr[j];
				arr[j] = c;
			}
			return arr;
		}

		int[] uniq(int[] arr) {
			arr = scn.shuffle(arr);
			Arrays.sort(arr);
			int[] rv = new int[arr.length];
			int pos = 0;
			rv[pos++] = arr[0];
			for (int i = 1; i < arr.length; i++) {
				if (arr[i] != arr[i - 1]) {
					rv[pos++] = arr[i];
				}
			}
			return Arrays.copyOf(rv, pos);
		}

		long[] uniq(long[] arr) {
			arr = scn.shuffle(arr);
			Arrays.sort(arr);
			long[] rv = new long[arr.length];
			int pos = 0;
			rv[pos++] = arr[0];
			for (int i = 1; i < arr.length; i++) {
				if (arr[i] != arr[i - 1]) {
					rv[pos++] = arr[i];
				}
			}
			return Arrays.copyOf(rv, pos);
		}

		int[] reverse(int[] arr) {
			int l = 0, r = arr.length - 1;
			while (l < r) {
				arr[l] = arr[l] ^ arr[r];
				arr[r] = arr[l] ^ arr[r];
				arr[l] = arr[l] ^ arr[r];
				l++;
				r--;
			}
			return arr;
		}

		long[] reverse(long[] arr) {
			int l = 0, r = arr.length - 1;
			while (l < r) {
				arr[l] = arr[l] ^ arr[r];
				arr[r] = arr[l] ^ arr[r];
				arr[l] = arr[l] ^ arr[r];
				l++;
				r--;
			}
			return arr;
		}

		int[] compress(int[] arr) {
			int n = arr.length;
			int[] rv = Arrays.copyOf(arr, n);
			rv = uniq(rv);
			for (int i = 0; i < n; i++) {
				arr[i] = Arrays.binarySearch(rv, arr[i]);
			}
			return arr;
		}

		long[] compress(long[] arr) {
			int n = arr.length;
			long[] rv = Arrays.copyOf(arr, n);
			rv = uniq(rv);
			for (int i = 0; i < n; i++) {
				arr[i] = Arrays.binarySearch(rv, arr[i]);
			}
			return arr;
		}
	}
}


import java.io.*;
import java.util.*;

public class B implements Runnable {
	FastReader scn;
	PrintWriter out;
	String INPUT = "";

	void solve() {
		int n = scn.nextInt(), ans = 0;
		char[] s = scn.next().toCharArray();

		int[][] arr = scn.next2DInt(n, 2);
		for(int i = 0; i < 1000; i++) {
			int curr = 0;
			for(int j = 0; j < n; j++) {
				int a = arr[j][0], b = arr[j][1];
				if(i < b || (i - b) % (2 * a) >= a) {
					curr += s[j] - '0';
				} else {
					curr += '1' - s[j];
				}
			}
			ans = Math.max(ans, curr);
		}
		out.println(ans);
	}

	public void run() {
		long time = System.currentTimeMillis();
		boolean oj = System.getProperty("ONLINE_JUDGE") != null;
		out = new PrintWriter(System.out);
		scn = new FastReader(oj);
		solve();
		out.flush();
		if (!oj) {
			System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" }));
		}
	}

	public static void main(String[] args) {
		new Thread(null, new B(), "Main", 1 << 26).start();
	}

	class FastReader {
		InputStream is;

		public FastReader(boolean onlineJudge) {
			is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		}

		byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

		int readByte() {
			if (lenbuf == -1)
				throw new InputMismatchException();
			if (ptrbuf >= lenbuf) {
				ptrbuf = 0;
				try {
					lenbuf = is.read(inbuf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return -1;
			}
			return inbuf[ptrbuf++];
		}

		boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b))
				;
			return b;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		char nextChar() {
			return (char) skip();
		}

		String next() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		String nextLine() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while ((!isSpaceChar(b) || b == ' ')) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		char[] next(int n) {
			char[] buf = new char[n];
			int b = skip(), p = 0;
			while (p < n && !(isSpaceChar(b))) {
				buf[p++] = (char) b;
				b = readByte();
			}
			return n == p ? buf : Arrays.copyOf(buf, p);
		}

		int nextInt() {
			int num = 0, b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		long nextLong() {
			long num = 0;
			int b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		char[][] nextMatrix(int n, int m) {
			char[][] map = new char[n][];
			for (int i = 0; i < n; i++)
				map[i] = next(m);
			return map;
		}

		int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		int[][] next2DInt(int n, int m) {
			int[][] arr = new int[n][];
			for (int i = 0; i < n; i++) {
				arr[i] = nextIntArray(m);
			}
			return arr;
		}

		long[][] next2DLong(int n, int m) {
			long[][] arr = new long[n][];
			for (int i = 0; i < n; i++) {
				arr[i] = nextLongArray(m);
			}
			return arr;
		}

		int[] shuffle(int[] arr) {
			Random r = new Random();
			for (int i = 1, j; i < arr.length; i++) {
				j = r.nextInt(i);
				int c = arr[i];
				arr[i] = arr[j];
				arr[j] = c;
			}
			return arr;
		}

		long[] shuffle(long[] arr) {
			Random r = new Random();
			for (int i = 1, j; i < arr.length; i++) {
				j = r.nextInt(i);
				long c = arr[i];
				arr[i] = arr[j];
				arr[j] = c;
			}
			return arr;
		}

		int[] uniq(int[] arr) {
			arr = scn.shuffle(arr);
			Arrays.sort(arr);
			int[] rv = new int[arr.length];
			int pos = 0;
			rv[pos++] = arr[0];
			for (int i = 1; i < arr.length; i++) {
				if (arr[i] != arr[i - 1]) {
					rv[pos++] = arr[i];
				}
			}
			return Arrays.copyOf(rv, pos);
		}

		long[] uniq(long[] arr) {
			arr = scn.shuffle(arr);
			Arrays.sort(arr);
			long[] rv = new long[arr.length];
			int pos = 0;
			rv[pos++] = arr[0];
			for (int i = 1; i < arr.length; i++) {
				if (arr[i] != arr[i - 1]) {
					rv[pos++] = arr[i];
				}
			}
			return Arrays.copyOf(rv, pos);
		}

		int[] reverse(int[] arr) {
			int l = 0, r = arr.length - 1;
			while (l < r) {
				arr[l] = arr[l] ^ arr[r];
				arr[r] = arr[l] ^ arr[r];
				arr[l] = arr[l] ^ arr[r];
				l++;
				r--;
			}
			return arr;
		}

		long[] reverse(long[] arr) {
			int l = 0, r = arr.length - 1;
			while (l < r) {
				arr[l] = arr[l] ^ arr[r];
				arr[r] = arr[l] ^ arr[r];
				arr[l] = arr[l] ^ arr[r];
				l++;
				r--;
			}
			return arr;
		}

		int[] compress(int[] arr) {
			int n = arr.length;
			int[] rv = Arrays.copyOf(arr, n);
			rv = uniq(rv);
			for (int i = 0; i < n; i++) {
				arr[i] = Arrays.binarySearch(rv, arr[i]);
			}
			return arr;
		}

		long[] compress(long[] arr) {
			int n = arr.length;
			long[] rv = Arrays.copyOf(arr, n);
			rv = uniq(rv);
			for (int i = 0; i < n; i++) {
				arr[i] = Arrays.binarySearch(rv, arr[i]);
			}
			return arr;
		}
	}
}


import java.util.Scanner;

public class second {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		String str = s.next();
		int[] a = new int[n];
		int[] b = new int[n];
		for (int i = 0; i < b.length; i++) {
			a[i] = s.nextInt();
			b[i] = s.nextInt();
		}
		int[] l = new int[n];
		int x=0;
		for (int i = 0; i < n; i++) {
			l[i] = str.charAt(i)-48;
			//System.out.print(l[i]+" ");
			if(l[i]==1) {
				x++;
			}

		}
		//System.out.println();
		int[] c = new int[1000];
		c[0]=x;
		int p = 1;
		for (int i = 0; i <n; i++) {

			if (l[i] == 0) {
				p = 0;
			}
			else {
				p=1;
			}
			int k = 0;
			for (int j = 1; j < c.length; j++) {

				if (j % (b[i] + (k * a[i])) == 0) {
					if (p == 1) {
						p = 0;
					} else {
						p = 1;
					}
					k++;
				}
				//System.out.println(j+" "+p);
				c[j] += p;
			}
//			System.out.println();
//			for (int j = 0; j < c.length; j++) {
//				System.out.print(c[j]+" ");
//			}
		}
		//System.out.println();
		int max = 0;
		int y=0;
		for (int i = 0; i < c.length; i++) {
			//System.out.print(c[i]+" ");
			if (c[i] > max) {
				max = c[i];
				y=i;
			}
		}
		//System.out.println();
		System.out.println(max);
	}
	/*
	 * 3 101 3 3 3 2 3 1 4 1111 3 4 5 2 3 1 3 2 6 011100 5 3 5 5 2 4 3 5 4 2 1 5
	 */

}


import java.util.Scanner;

public class second {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		String str = s.next();
		int[] a = new int[n];
		int[] b = new int[n];
		for (int i = 0; i < b.length; i++) {
			a[i] = s.nextInt();
			b[i] = s.nextInt();
		}
		int[] l = new int[n];
		int x=0;
		for (int i = 0; i < n; i++) {
			l[i] = str.charAt(i)-48;
			//System.out.print(l[i]+" ");
			if(l[i]==1) {
				x++;
			}

		}
		//System.out.println();
		int[] c = new int[100];
		c[0]=x;
		int p = 1;
		for (int i = 0; i <n; i++) {

			if (l[i] == 0) {
				p = 0;
			}
			else {
				p=1;
			}
			int k = 0;
			for (int j = 1; j < c.length; j++) {

				if (j % (b[i] + k * a[i]) == 0) {
					if (p == 1) {
						p = 0;
					} else {
						p = 1;
					}
					k++;
				}
				//System.out.println(j+" "+p);
				c[j] += p;
			}
//			System.out.println();
//			for (int j = 0; j < c.length; j++) {
//				System.out.print(c[j]+" ");
//			}
		}
		//System.out.println();
		int max = 0;
		int y=0;
		for (int i = 0; i < c.length; i++) {
			//System.out.print(c[i]+" ");
			if (c[i] > max) {
				max = c[i];
				y=i;
			}
		}
		//System.out.println();
		System.out.println(max);
	}
	/*
	 * 3 101 3 3 3 2 3 1 4 1111 3 4 5 2 3 1 3 2 6 011100 5 3 5 5 2 4 3 5 4 2 1 5
	 */

}


import java.util.Scanner;
import java.util.Arrays;
public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner (System.in);
		int n=input.nextInt();
		String str=input.nextLine();//分隔符
		str=input.nextLine();
		int []lights=new int[n*100],start=new int[n],sec=new int[n];
		for(int i=0;i<n;i++) {
			sec[i]=input.nextInt();
			start[i]=input.nextInt();
		}
		for(int i=0;i<n;i++) {
			char c=str.charAt(i);
			if(c=='1')	{
				for(int j=0;j<start[i];j++)
					lights[j]++;
				for(int j=1;j<=10;j+=2) {
					int time=start[i]+sec[i]*j;
					for(int k=time;k<time+sec[i];k++)
						lights[k]++;
				}
			}
			else {
				for(int j=0;j<=10;j+=2) {
					int time=start[i]+j*sec[i];
					for(int k=time;k<=time+sec[i];k++)
						lights[k]++;
				}
			}
		}

		Arrays.sort(lights);
		System.out.println(lights[lights.length-1]);
	}
}


import java.util.Scanner;
import java.util.Arrays;
public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner (System.in);
		int n=input.nextInt();
		String str=input.nextLine();//分隔符
		str=input.nextLine();
		int []lights=new int[n*1000],start=new int[n],sec=new int[n];
		for(int i=0;i<n;i++) {
			sec[i]=input.nextInt();
			start[i]=input.nextInt();
		}
		for(int i=0;i<n;i++) {
			char c=str.charAt(i);
			if(c=='1')	{
				for(int j=0;j<start[i];j++)
					lights[j]++;//初始时灯打开
				for(int j=1;j<=200;j+=2) {
					int time=start[i]+sec[i]*j;
					for(int k=time;k<time+sec[i];k++)
						lights[k]++;
				}
			}
			else {
				//c=='0'
				for(int j=1;j<=200;j+=2) {//初始时灯关闭
					int time=start[i]+(j-1)*sec[i];
					for(int k=time;k<time+sec[i];k++)
						lights[k]++;
				}
			}
		}
		Arrays.sort(lights);
		System.out.println(lights[lights.length-1]);
	}
}


import java.util.Scanner;
import java.util.Arrays;
public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner (System.in);
		int n=input.nextInt();
		String str=input.nextLine();//分隔符
		str=input.nextLine();
		int []lights=new int[n*1000],start=new int[n],sec=new int[n];
		for(int i=0;i<n;i++) {
			sec[i]=input.nextInt();
			start[i]=input.nextInt();
		}
		for(int i=0;i<n;i++) {
			char c=str.charAt(i);
			if(c=='1')	{
				for(int j=0;j<start[i];j++)
					lights[j]++;
				for(int j=1;j<=100;j+=2) {
					int time=start[i]+sec[i]*j;
					for(int k=time;k<time+sec[i];k++)
						lights[k]++;
				}
			}
			else {
				for(int j=0;j<=100;j+=2) {
					int time=start[i]+j*sec[i];
					for(int k=time;k<=time+sec[i];k++)
						lights[k]++;
				}
			}
		}

		Arrays.sort(lights);
		System.out.println(lights[lights.length-1]);
	}
}


import java.util.Scanner;
import java.util.Arrays;
public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner (System.in);
		int n=input.nextInt();
		String str=input.nextLine();//分隔符
		str=input.nextLine();
		int []lights=new int[n*1000],start=new int[n],sec=new int[n];
		for(int i=0;i<n;i++) {
			sec[i]=input.nextInt();
			start[i]=input.nextInt();
		}
		for(int i=0;i<n;i++) {
			char c=str.charAt(i);
			if(c=='1')	{
				for(int j=0;j<start[i];j++)
					lights[j]++;//初始时灯打开
				for(int j=1;j<=20;j+=2) {
					int time=start[i]+sec[i]*j;
					for(int k=time;k<time+sec[i];k++)
						lights[k]++;
				}
			}
			else {

				//c=='0'
				for(int j=1;j<=20;j+=2) {//初始时灯关闭
					int time=start[i]+(j-1)*sec[i];
					for(int k=time;k<time+sec[i];k++)
						lights[k]++;
				}
			}
		}
		Arrays.sort(lights);
		System.out.println(lights[lights.length-1]);
	}
}


//package cf584d12;
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class B {
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		boolean[] on = new boolean[n];
		char[] s = sc.nextLine().toCharArray();
		for(int i = 0; i < n; i++)
			on[i] = s[i] == '1';
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		int max = 0;
		for(int i = 0; i < 1000; i++) {
			for(int j = 0; j < n; j++)
				if(i > b[j] && ((i - b[j]) % a[j]) == 0)
					on[j] = !on[j];
			int ct = 0;
			for(int j = 0; j < n; j++)
				if(on[j])
					ct++;
			max = max(max, ct);
		}
		out.println(max);
		out.close();
	}
	public static PrintWriter out  = new PrintWriter(new BufferedOutputStream(System.out));
	public static class MyScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		String next() {
			while (st == null || !st.hasMoreElements())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


//package cf584d12;
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class B {
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		boolean[] on = new boolean[n];
		char[] s = sc.nextLine().toCharArray();
		for(int i = 0; i < n; i++)
			on[i] = s[i] == '1';
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		int max = 0;
		for(int i = 0; i < 1000; i++) {
			for(int j = 0; j < n; j++)
				if(i >= b[j] && ((i - b[j]) % a[j]) == 0)
					on[j] = !on[j];
			int ct = 0;
			for(int j = 0; j < n; j++)
				if(on[j])
					ct++;
			max = max(max, ct);
		}
		out.println(max);
		out.close();
	}
	public static PrintWriter out  = new PrintWriter(new BufferedOutputStream(System.out));
	public static class MyScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		String next() {
			while (st == null || !st.hasMoreElements())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


import java.io.*;
import java.util.*;

public class A {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		char[] s = sc.next().toCharArray();
		int[] a = new int[n], b = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		int ans = 0;
		for (int t = 0; t <= (int) 1e4; t++) {
			int curr = 0;
			for (int i = 0; i < n; i++) {
				if (t >= b[i] && (t - b[i]) % a[i] == 0) {
					s[i] = s[i] == '1' ? '0' : '1';
				}
				if (s[i] == '1')
					curr++;
			}
			ans = Math.max(ans, curr);
		}
		out.println(ans);
		out.close();

	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		Scanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		boolean ready() throws IOException {
			return br.ready();
		}

	}

	static void sort(int[] a) {
		shuffle(a);
		Arrays.sort(a);
	}

	static void shuffle(int[] a) {
		int n = a.length;
		Random rand = new Random();
		for (int i = 0; i < n; i++) {
			int tmpIdx = rand.nextInt(n);
			int tmp = a[i];
			a[i] = a[tmpIdx];
			a[tmpIdx] = tmp;
		}
	}

}


import java.io.*;
import java.util.*;
import java.util.Map.*;
import java.math.*;
//import java.lang.*;

public class q2
{
    static int MOD=1000000007;
    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[1000000]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

    static boolean isPrime(int n)
    {
        if (n <= 1)
            return false;
        if (n <= 3)
            return true;
        if (n % 2 == 0 || n % 3 == 0)
            return false;

        for (int i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 ||  n % (i + 2) == 0)
                return false;

        return true;
    }
    static int gcd(int a, int b)
    {
      if (b == 0)
        return a;
      return gcd(b, a % b);
    }
    //Functions
    static int sum(int arr[])
    {
        int sum = 0; // initialize sum
        int i;

        // Iterate through all elements and add them to sum
        for (i = 0; i < arr.length; i++)
           sum +=  arr[i];

        return sum;
    }

    public static void main(String[] args) throws IOException
    {
       Scanner sc=new Scanner(System.in);
       //int T=sc.nextInt();
       int T=1;
       while(T-- > 0){
           int N=sc.nextInt();
           String s =sc.next();
           int A[]=new int[N];
           int B[]=new int[N];
           int bulb[]=new int[N];
           int bulb_i[]=new int[N];
           int count=0;
           int ans=0;
           boolean flag=false;

           for(int i=0;i<N;++i){
               A[i]=sc.nextInt();
               B[i]=sc.nextInt();
               bulb[i]=Character.getNumericValue(s.charAt(i));
               bulb_i[i]=Character.getNumericValue(s.charAt(i));
           }
           int max=0;
           int time=10000;
           int t=0;
           while(t<=time){
               int sum2=sum(bulb);
               if(sum2>max)
                    max=sum2;
               // System.out.println(max);
               for(int i=0;i<N;++i){
                if(t<B[i])
                    continue;
                int flip=(int)Math.floor((double)(t-B[i])/A[i]);
                if(flip%2 ==0 )
                    {
                        if(bulb_i[i]==1)
                            bulb[i]=0;
                        else
                            bulb[i]=1;
                    }
                else
                    bulb[i]=bulb_i[i];
               }
               t++;

           }

           System.out.println(max);
        } // End of test cases loop

    }//end of main function

} //end of class


import java.util.*;
public class Main {
    public static void main(String[] args) {
        int seconds = 0, maxrate=0, result=0, maxon=0;
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Boolean[] state = new Boolean[n];
        Integer[] rate = new Integer[n], start = new Integer[n], round = new Integer[n];
        String s = scanner.nextLine();
        s = scanner.nextLine();
        char[] stateCh = new char[n];
        stateCh = s.toCharArray();
        for(int i = 0; i<n;i++)
            state[i] = stateCh[i] == '1' ? true : false;
        for(int i = 0; i<n;i++) {
            rate[i] = scanner.nextInt();
            start[i] = scanner.nextInt();
            round[i] = 1;
            maxrate = Math.max(maxrate, rate[i]);
        }

        while(seconds < maxrate*2*n + maxrate){
            for(int i = 0; i<state.length;i++){
                if(seconds >= start[i]){
                    if(seconds == start[i])
                        state[i] = state[i] == true ? state[i] = false : (state[i] = true);
                    else if(seconds == start[i] + rate[i]*round[i])
                    {
                        state[i] = state[i] == true ? state[i] = false : (state[i] = true);
                        round[i]++;
                    }
                }
                if(state[i]) maxon++;
            }
            result = Math.max(result, maxon);
            maxon = 0;
            seconds++;
        }
        System.out.println(result);
    }
}


import java.util.*;

public class Main {
    public static void main(String[] args) {
        int seconds = 0, maxrate=0, result=0, maxon=0;
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Boolean[] state = new Boolean[n];
        Integer[] rate = new Integer[n], start = new Integer[n], round = new Integer[n];
        String s = scanner.nextLine();
        s = scanner.nextLine();
        char[] stateCh = new char[n];
        stateCh = s.toCharArray();
        for(int i = 0; i<n;i++)
            state[i] = stateCh[i] == '1' ? true : false;
        for(int i = 0; i<n;i++) {
            rate[i] = scanner.nextInt();
            start[i] = scanner.nextInt();
            round[i] = 1;
            maxrate = Math.max(maxrate, rate[i]);
        }

        while(seconds < maxrate*2*n + maxrate){
            for(int i = 0; i<state.length;i++){
                if(seconds >= start[i]){
                    if(seconds == start[i])
                        state[i] = state[i] == true ? state[i] = false : (state[i] = true);
                    else if(seconds == start[i] + rate[i]*round[i])
                    {
                        state[i] = state[i] == true ? state[i] = false : (state[i] = true);
                        round[i]++;
                    }
                }
                if(state[i]) maxon++;
            }
            result = Math.max(result, maxon);
            maxon = 0;
            seconds++;
        }
        System.out.println(result);
        System.out.println(seconds);
    }
}


import java.util.*;
public class Main {
    public static void main(String[] args) {
        int seconds = 0, maxrate=0, result=0, maxon=0;
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Boolean[] state = new Boolean[n];
        Integer[] rate = new Integer[n], start = new Integer[n], round = new Integer[n];
        String s = scanner.nextLine();
        s = scanner.nextLine();
        char[] stateCh = new char[n];
        stateCh = s.toCharArray();
        for(int i = 0; i<n;i++)
            state[i] = stateCh[i] == '1' ? true : false;
        for(int i = 0; i<n;i++) {
            rate[i] = scanner.nextInt();
            start[i] = scanner.nextInt();
            round[i] = 1;
            maxrate = Math.max(maxrate, rate[i]);
        }

        while(seconds < maxrate*4*n + maxrate){
            for(int i = 0; i<state.length;i++){
                if(seconds >= start[i]){
                    if(seconds == start[i])
                        state[i] = state[i] == true ? state[i] = false : (state[i] = true);
                    else if(seconds == start[i] + rate[i]*round[i])
                    {
                        state[i] = state[i] == true ? state[i] = false : (state[i] = true);
                        round[i]++;
                    }
                }
                if(state[i]) maxon++;
            }
            result = Math.max(result, maxon);
            maxon = 0;
            seconds++;
        }
        System.out.println(result);
        System.out.println(seconds);
    }
}


import java.util.*;
public class Main {
    public static void main(String[] args) {
        int seconds = 0, maxrate=0, result=0, maxon=0;
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Boolean[] state = new Boolean[n];
        Integer[] rate = new Integer[n], start = new Integer[n], round = new Integer[n];
        String s = scanner.nextLine();
        s = scanner.nextLine();
        char[] stateCh = new char[n];
        stateCh = s.toCharArray();
        for(int i = 0; i<n;i++)
            state[i] = stateCh[i] == '1' ? true : false;
        for(int i = 0; i<n;i++) {
            rate[i] = scanner.nextInt();
            start[i] = scanner.nextInt();
            round[i] = 1;
            maxrate = Math.max(maxrate, rate[i]);
        }

        while(seconds < maxrate*2*n + maxrate){
            for(int i = 0; i<state.length;i++){
                if(seconds >= start[i]){
                    if(seconds == start[i])
                        state[i] = state[i] == true ? state[i] = false : (state[i] = true);
                    else if(seconds == start[i] + rate[i]*round[i])
                    {
                        state[i] = true ? state[i] = false : (state[i] = true);
                        round[i]++;
                    }
                }
                if(state[i]) maxon++;
            }
            result = Math.max(result, maxon);
            maxon = 0;
            seconds++;
        }
        System.out.println(result);
    }
}