static long solve ( ) {
  int [ ] candyInR = new int [ r + 1 ] ;
  int [ ] candyInC = new int [ c + 1 ] ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    candyInR [ rc [ i ] ] ++ ;
    candyInC [ cc [ i ] ] ++ ;
  }
  int [ ] countR = new int [ n + 1 ] ;
  int [ ] countC = new int [ n + 1 ] ;
  for ( int i = 0 ;
  i < r ;
  i ++ ) countR [ candyInR [ i ] ] ++ ;
  for ( int i = 0 ;
  i < c ;
  i ++ ) countC [ candyInC [ i ] ] ++ ;
  long ans = 0 ;
  for ( int i = 0 ;
  i <= k ;
  i ++ ) ans += countR [ i ] * countC [ k - i ] ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    int sum = candyInR [ rc [ i ] ] + candyInC [ cc [ i ] ] ;
    if ( sum == k ) ans -- ;
    if ( sum == k + 1 ) ans ++ ;
  }
  return ans ;
}

static long solve ( ) { int [ ] candyInR = new int [ r + 1 ] ; int [ ] candyInC = new int [ c + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { candyInR [ rc [ i ] ] ++ ; candyInC [ cc [ i ] ] ++ ; } int [ ] countR = new int [ n + 1 ] ; int [ ] countC = new int [ n + 1 ] ; for ( int i = 0 ; i < r ; i ++ ) countR [ candyInR [ i ] ] ++ ; for ( int i = 0 ; i < c ; i ++ ) countC [ candyInC [ i ] ] ++ ; long ans = 0 ; for ( int i = 0 ; i <= k ; i ++ ) ans += countR [ i ] * countC [ k - i ] ; for ( int i = 0 ; i < n ; i ++ ) { int sum = candyInR [ rc [ i ] ] + candyInC [ cc [ i ] ] ; if ( sum == k ) ans -- ; if ( sum == k + 1 ) ans ++ ; } return ans ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters) body: (block (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 (binary_expression left: (identifier) right: (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 (binary_expression left: (identifier) 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 (expression_statement (update_expression (array_access array: (identifier) index: (array_access array: (identifier) index: (identifier))))) (expression_statement (update_expression (array_access array: (identifier) index: (array_access array: (identifier) index: (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 (binary_expression left: (identifier) right: (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 (binary_expression left: (identifier) 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: (expression_statement (update_expression (array_access array: (identifier) index: (array_access array: (identifier) index: (identifier)))))) (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: (expression_statement (update_expression (array_access array: (identifier) index: (array_access array: (identifier) index: (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (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: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (identifier))))))) (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: (binary_expression left: (array_access array: (identifier) index: (array_access array: (identifier) index: (identifier))) right: (array_access array: (identifier) index: (array_access array: (identifier) index: (identifier)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (update_expression (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (expression_statement (update_expression (identifier)))))) (return_statement (identifier))))