def calculate_distance(permutation, distances):
    """
    Sum up all distances between locations for given permutation

    Args:
        permutation (tuple): locations in specific order
        distances (dict) : nested dictionary of locations

    Returns:
        int: total distance between locations
    """
    permutation_distance = 0
    for x in range(7):
        number = distances[permutation[x]][permutation[x+1]]
        permutation_distance += distances[permutation[x]][permutation[x+1]]
    
    return permutation_distance