public static void main ( String [ ] args ) {
  Scanner omkar = new Scanner ( System . in ) ;
  int n = omkar . nextInt ( ) ;
  int m = omkar . nextInt ( ) ;
  int u = gcd ( m , n ) ;
  int [ ] b = new int [ n ] ;
  int [ ] g = new int [ m ] ;
  int x = omkar . nextInt ( ) ;
  for ( int i = 0 ;
  i < x ;
  i ++ ) {
    b [ omkar . nextInt ( ) ] = 1 ;
  }
  int y = omkar . nextInt ( ) ;
  for ( int i = 0 ;
  i < y ;
  i ++ ) {
    g [ omkar . nextInt ( ) ] = 1 ;
  }
  for ( int i = 0 ;
  i < u ;
  i ++ ) {
    if ( ! test ( b , g , u , i ) ) {
      System . out . println ( "No" ) ;
      return ;
    }
  }
  System . out . println ( "Yes" ) ;
}

public static void main ( String [ ] args ) { Scanner omkar = new Scanner ( System . in ) ; int n = omkar . nextInt ( ) ; int m = omkar . nextInt ( ) ; int u = gcd ( m , n ) ; int [ ] b = new int [ n ] ; int [ ] g = new int [ m ] ; int x = omkar . nextInt ( ) ; for ( int i = 0 ; i < x ; i ++ ) { b [ omkar . nextInt ( ) ] = 1 ; } int y = omkar . nextInt ( ) ; for ( int i = 0 ; i < y ; i ++ ) { g [ omkar . nextInt ( ) ] = 1 ; } for ( int i = 0 ; i < u ; i ++ ) { if ( ! test ( b , g , u , i ) ) { System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; }
(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: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (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: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier))))) (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))))) (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))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) 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 (expression_statement (assignment_expression left: (array_access array: (identifier) index: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) right: (decimal_integer_literal))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) 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 (expression_statement (assignment_expression left: (array_access array: (identifier) index: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) right: (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 (if_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier) (identifier))))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))) (return_statement))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal))))))