Dots......... X52291


Statement
 

pdf   zip

html

We have a rectangle subdivided into squares. In each square there are some of dots.

By clicking on a line which separates two squares, we make this line disappear, merging the two squares into a rectangle. Then, we can merge rectangles into bigger rectangles, and so on. We play until all lines disappear, and we obtain a rectangle without lines, filled with dots.

Sometimes merging two rectangles is rewarded. Let d1 and d2 be the numbers of dots in the two merged rectangles. It is worth it to merge rectangles which have a similar number of dots: if |d1d2| ≤ M, we get K bonus dots. Additionally, if d1+d2 is divisible by K, we get N bonus dots. All bonus dots appear in the merged square (instead of the line which was removed).

The goal of the game is to obtain as many dots in total as possible.

Input

The first line contains five numbers: X, Y, K, N, M. We have 1 ≤ X ≤ 15, 1 ≤ Y ≤ 15, 2 ≤ K ≤ 10, 0 ≤ N ≤ 1000000, 0 ≤ M ≤ 1000003.

The following Y lines describe the amount of dots in each square. ith of these lines contains X numbers ai,1, ai,2, …, ai,X, where ai,j is the number of dots in the square in row i, column j (1 ≤ ai,j ≤ 1000000).

Output

Output the highest number of dots that can be obtained in the end.

Public test cases
  • Input

    2 2 10 1000 1
    4 6
    7 3
    

    Output

    3030
    
  • Information
    Author
    Eryk Kopczynski
    Language
    English
    Official solutions
    Unknown.
    User solutions
    C++