public static void main ( String [ ] args ) throws Exception {
  int n = in . readInt ( ) ;
  char [ ] init = in . readLine ( ) . toCharArray ( ) ;
  int [ ] time = new int [ 1000 ] ;
  int [ ] [ ] bulb = new int [ n ] [ ] ;
  int ans = 0 , mxt = - 1 ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    bulb [ i ] = in . readA ( ) ;
    boolean state = init [ i ] == '1' ? true : false ;
    for ( int t = 0 ;
    t < time . length ;
    t ++ ) {
      if ( t >= bulb [ i ] [ 1 ] && ( t - bulb [ i ] [ 1 ] ) % bulb [ i ] [ 0 ] == 0 ) state = ! state ;
      if ( state ) time [ t ] ++ ;
      if ( time [ t ] > ans ) {
        mxt = t ;
        ans = time [ t ] ;
      }
    }
  };
}

public static void main ( String [ ] args ) throws Exception { int n = in . readInt ( ) ; char [ ] init = in . readLine ( ) . toCharArray ( ) ; int [ ] time = new int [ 1000 ] ; int [ ] [ ] bulb = new int [ n ] [ ] ; int ans = 0 , mxt = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { bulb [ i ] = in . readA ( ) ; boolean state = init [ i ] == '1' ? true : false ; for ( int t = 0 ; t < time . length ; t ++ ) { if ( t >= bulb [ i ] [ 1 ] && ( t - bulb [ i ] [ 1 ] ) % bulb [ i ] [ 0 ] == 0 ) state = ! state ; if ( state ) time [ t ] ++ ; if ( time [ t ] > ans ) { mxt = t ; ans = time [ t ] ; } } } ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) (throws (type_identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (decimal_integer_literal))))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier)) dimensions: (dimensions)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (unary_expression operand: (decimal_integer_literal)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (boolean_type) declarator: (variable_declarator name: (identifier) value: (ternary_expression condition: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (character_literal)) consequence: (true) alternative: (false)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (field_access object: (identifier) field: (identifier))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal))) right: (binary_expression left: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)))) right: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal))) right: (decimal_integer_literal)))) consequence: (expression_statement (assignment_expression left: (identifier) right: (unary_expression operand: (identifier))))) (if_statement condition: (parenthesized_expression (identifier)) consequence: (expression_statement (update_expression (array_access array: (identifier) index: (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (identifier))))))))))))