You've got an *n* × *m* pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.

A picture is a barcode if the following conditions are fulfilled: 
 -  All pixels in each column are of the same color. -  The width of each monochrome vertical line is at least *x* and at most *y* pixels. In other words, if we group all neighbouring columns of the pixels with equal color, the size of each group can not be less than *x* or greater than *y*.
The first line contains four space-separated integers *n*, *m*, *x* and *y* (1 ≤ *n*, *m*, *x*, *y* ≤ 1000; *x* ≤ *y*).

Then follow *n* lines, describing the original image. Each of these lines contains exactly *m* characters. Character "." represents a white pixel and "#" represents a black pixel. The picture description doesn't have any other characters besides "." and "#".
def main():
    n, m, x, y = list(map(int, input().split()))
    G = []
    for _ in range(n):
        G.append(input())

    H = [0] * m # count in the given row
    for i in range(m):
        Hcount = 0
        for j in range(n):
            if G[j][i] == '#':
                Hcount += 1
        H[i] = (Hcount)
    X = [[0] * 3 for _ in range(m)]
    X[0][1], X[0][2], X[0][0] = (n - H[0]), H[0], min((n - H[0], H[0]))
    Consec = [[1] * 3 for _ in range(m)]
    for i in range(1, m):
        tmp1, tmp2, tmp3 = float('inf'), float('inf'), float('inf')
        if Consec[i - 1][2] >= x: # Change
            tmp1 = X[i - 1][2] + (n - H[i]) # dots to conv to hash
        if Consec[i - 1][1] + 1 <= y:
            tmp2 = X[i - 1][1] + (n - H[i])
        else:
            tmp3 = X[i - 1][0] + H[i]
        if tmp1 == min(tmp1, tmp2, tmp3):
            X[i][1], Consec[i][1] = tmp1, 1
        elif tmp2 == min(tmp1, tmp2, tmp3):
            X[i][1], Consec[i][1] = tmp2, 1 + Consec[i - 1][1]
        else:
            X[i][1], Consec[i][1] = tmp3, 1

        tmp1, tmp2, tmp3 = float('inf'), float('inf'), float('inf')    
        

        if Consec[i - 1][1] >= x:
            tmp1 = X[i - 1][0] + (H[i])
        if Consec[i - 1][2] + 1 <= y:
            tmp2 = X[i - 1][2] + (H[i])
        else:
            tmp3 = X[i - 1][0] + (n - H[i])
        
        
        if tmp1 == min(tmp1, tmp2, tmp3):
            X[i][2], Consec[i][2] = tmp1, 1
        elif tmp2 == min(tmp1, tmp2, tmp3):
            X[i][2], Consec[i][2] = tmp2, 1 + Consec[i - 1][2]
        else:
            X[i][2] = tmp3, 1
        
        X[i][0] = min(X[i][1], X[i][2])
    print(X[m - 1][0])

if __name__ == "__main__":
    main()