def find_anomalies(X, T1, T2):
    anomalies = []
    for i, value in enumerate(X):
        if value < T1 or value > T2:
            anomalies.append(i)
    return anomalies


def correct_anomalies(X, anomalies):
    if not anomalies:
        return X

    X_list = list(X)
    n = len(X_list)
    avg_value = sum(X_list) / n

    for idx in anomalies:
        if idx == 0 or idx == n - 1:
            X_list[idx] = avg_value
        else:
            X_list[idx] = (X_list[idx - 1] + X_list[idx + 1]) / 2

    return tuple(X_list)