public static void main ( String [ ] $ ) {
  int n = gInt ( ) ;
  long a = gInt ( ) , b = gInt ( ) ;
  for ( int i = 1 ;
  i < n ;
  ++ i ) {
    int A = gInt ( ) , B = gInt ( ) ;
    if ( a * 1.0 / A < b * 1.0 / B ) {
      b = ( b + B - 1 ) / B * B ;
      a = b / B * A ;
    }
    else {
      a = ( a + A - 1 ) / A * A ;
      b = a / A * B ;
    }
  }
  System . out . println ( a + b ) ;
}

public static void main ( String [ ] $ ) { int n = gInt ( ) ; long a = gInt ( ) , b = gInt ( ) ; for ( int i = 1 ; i < n ; ++ i ) { int A = gInt ( ) , B = gInt ( ) ; if ( a * 1.0 / A < b * 1.0 / B ) { b = ( b + B - 1 ) / B * B ; a = b / B * A ; } else { a = ( a + A - 1 ) / A * A ; b = a / A * B ; } } System . out . println ( a + b ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list))) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list)))) (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 (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list))) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list)))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (decimal_floating_point_literal)) right: (identifier)) right: (binary_expression left: (binary_expression left: (identifier) right: (decimal_floating_point_literal)) right: (identifier)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (binary_expression left: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal))) right: (identifier)) right: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier))))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (binary_expression left: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal))) right: (identifier)) right: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier)))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier)))))))