import xlrd
import xlsxwriter

def remove_duplicates(input_file, output_file):
    # Open input XLS file
    workbook = xlrd.open_workbook(input_file)
    sheet = workbook.sheet_by_index(0)

    # Dictionary to store first occurrences of duplicates
    first_occurrences = {}

    # List of rows to keep
    rows_to_keep = []

    # Iterate over rows
    for row_index in range(sheet.nrows):
        key = sheet.cell_value(row_index, 0)   # Value from first column
        value = sheet.cell_value(row_index, 2) # Value from third column

        # If this key and value pair already appeared
        if (key, value) in first_occurrences.values():
            continue  # Skip this duplicate row
        else:
            # Store first occurrence
            first_occurrences[row_index] = (key, value)
            # Add row to keep
            rows_to_keep.append(row_index)

    # Write kept rows to new Excel file
    workbook_out = xlsxwriter.Workbook(output_file)
    worksheet_out = workbook_out.add_worksheet()

    # Copy rows to output file
    for new_row_index, old_row_index in enumerate(rows_to_keep):
        for col_index in range(sheet.ncols):
            cell_value = sheet.cell_value(old_row_index, col_index)
            worksheet_out.write(new_row_index, col_index, cell_value)

    workbook_out.close()

# File parameters
input_file = "MM.xls"
output_file = "MM.xlsx"

# Remove duplicates and save result
remove_duplicates(input_file, output_file)