def find_anomal(X, M1, M2):

    K = []
    for i in range(1, len(X)):
        diff = X[i] - X[i - 1]
        if diff < M1 or diff > M2:
            K.append(i)
    return tuple(K)

def cor_anom(X, K):
   
    X1 = X.copy()
    n = len(X)
    
    for idx in K:
        if idx == n - 1:
            X1[idx] = X[idx - 1]
        elif idx == 0:
            X1[idx] = X[idx + 1]
        else:
            X1[idx] = 0.5 * (X[idx - 1] + X[idx + 1])
    
    return X1
