MaxSum (Happy Sum - 1)
You have a rectangular table with N rows and M columns, where each cell contains an integer. You can traverse the table from top to bottom, starting from any cell in the top row. From each cell (i, j), you can move to one of the "lower neighboring" cells: (i+1, j-1), (i+1, j), or (i+1, j+1). Note that if j=M, you cannot move to (i+1, j+1), and if j=1, you cannot move to (i+1, j-1). You finish your path in any cell of the bottom row.
Your task is to write a program that finds the maximum possible "happy sum" of the values along any valid path. A "happy number" is a natural number whose decimal representation consists only of the digits 4 and 7. For example, 47, 744, and 4 are happy numbers, while 0, 5, 17, and 467 are not. Note that the sum itself must be a happy number, not the individual numbers in the path.
Input
The first line contains two integers, N and M, representing the number of rows and columns respectively (1 ≤ N, M ≤ 77). Each of the next N lines contains M space-separated integers, each in the range 0 ≤ a_{ij} ≤ 77, representing the values in the table cells.
Output
Output a single integer, which is the maximum happy sum found among all valid paths. If no such path exists with a happy sum, output the string "impossible" (in lowercase, without quotes).