Optimization: repeated_element_in_col and repeated_element_in_row