def scorefunction(tree, dataset):
    """
    This function checks every row in dataset, calculating the output from the function
    and comparing it to the real result. It adds up all the diffences, giving lower
    values for better programs.

    Return value 0 indicates that the program got every result correct
    """
    dif = 0
    for data in dataset:
        v = tree.evaluate([data[0], data[1]])
        dif += abs(v - data[2])
    return dif