public static void DrazilAndHisHappyFriends ( ) {
  int n = scan . nextInt ( ) ;
  int m = scan . nextInt ( ) ;
  boolean [ ] boys = new boolean [ n ] ;
  boolean [ ] girls = new boolean [ m ] ;
  int happy_boys = scan . nextInt ( ) ;
  while ( happy_boys -- > 0 ) {
    boys [ scan . nextInt ( ) ] = true ;
  }
  int happy_girls = scan . nextInt ( ) ;
  while ( happy_girls -- > 0 ) {
    girls [ scan . nextInt ( ) ] = true ;
  }
  for ( int i = 0 ;
  i < ( n + m ) * n * m ;
  i ++ ) {
    if ( boys [ i % n ] || girls [ i % m ] ) {
      boys [ i % n ] = girls [ i % m ] = true ;
    }
  }
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    if ( ! boys [ i ] ) {
      System . out . println ( "No" ) ;
      return ;
    }
  }
  for ( int i = 0 ;
  i < m ;
  i ++ ) {
    if ( ! girls [ i ] ) {
      System . out . println ( "No" ) ;
      return ;
    }
  }
  System . out . println ( "Yes" ) ;
}

public static void DrazilAndHisHappyFriends ( ) { int n = scan . nextInt ( ) ; int m = scan . nextInt ( ) ; boolean [ ] boys = new boolean [ n ] ; boolean [ ] girls = new boolean [ m ] ; int happy_boys = scan . nextInt ( ) ; while ( happy_boys -- > 0 ) { boys [ scan . nextInt ( ) ] = true ; } int happy_girls = scan . nextInt ( ) ; while ( happy_girls -- > 0 ) { girls [ scan . nextInt ( ) ] = true ; } for ( int i = 0 ; i < ( n + m ) * n * m ; i ++ ) { if ( boys [ i % n ] || girls [ i % m ] ) { boys [ i % n ] = girls [ i % m ] = true ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( ! boys [ i ] ) { System . out . println ( " No " ) ; return ; } } for ( int i = 0 ; i < m ; i ++ ) { if ( ! girls [ i ] ) { System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters) 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: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (array_type element: (boolean_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (boolean_type) dimensions: (dimensions_expr (identifier))))) (local_variable_declaration type: (array_type element: (boolean_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (boolean_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)))) (while_statement condition: (parenthesized_expression (binary_expression left: (update_expression (identifier)) right: (decimal_integer_literal))) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) right: (true))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (while_statement condition: (parenthesized_expression (binary_expression left: (update_expression (identifier)) right: (decimal_integer_literal))) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) right: (true))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (binary_expression left: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (identifier)) right: (identifier))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (identifier))) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (identifier))))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (identifier))) right: (assignment_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (identifier))) right: (true)))))))) (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: (array_access array: (identifier) index: (identifier)))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))) (return_statement))))) (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: (array_access array: (identifier) index: (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))))))