Under construction

Still being built. Things may change

Grayscale Photo

Time limit1sMemory limit512 MB

Summary
Count the color photos (RGB triples) whose floor average matches each given gray value, modulo 10007.
Level

Medium6 of 10

Topics
Combinatorics, Math, Dynamic programming
Solved
No attempts yet

Problem

Mirko got a digital camera as a birthday present and has been taking pictures ever since. Every day he shoots thousands of color photos, and when he gets home he prints them and sticks them on the walls. Mirko's printer is black and white, so every photo stored on the camera has to be turned into its gray version before printing.

The camera stores a photo like this. After the number of rows RR and the number of columns SS, the image file holds 3×R×S3 \times R \times S more numbers. Each pixel is written as three numbers, the intensities of red, green and blue. The intensities are integers from 00 to 255255 inclusive. A color pixel becomes the matching shade of gray by averaging those three values.

gray=⌊red+green+blue3⌋\text{gray} = \left\lfloor \frac{\text{red} + \text{green} + \text{blue}}{3} \right\rfloor

In the formula, ⌊x⌋\lfloor x \rfloor means rounding down. For example, ⌊0.3⌋=0\lfloor 0.3 \rfloor = 0, ⌊1.5⌋=1\lfloor 1.5 \rfloor = 1, ⌊2.9⌋=2\lfloor 2.9 \rfloor = 2.

One day Slavko came to Mirko's studio and teased him: "You don't even know that your printer prints a huge number of different photos the same way!" Mirko then wanted to know what that number is. To be precise, he wants to count the color photos that the formula above turns into the given gray photo. That count can be very large, so report its remainder when divided by 1000710007.

Input

The first line contains the number of rows RR and the number of columns SS of the gray photo. (1≤R≤10001 \le R \le 1000, 1≤S≤10001 \le S \le 1000)

Each of the next RR lines contains SS integers xr,sx_{r,s}. (0≤xr,s<2560 \le x_{r,s} < 256) These numbers are the gray shade of each pixel.

Output

Print the number of different color photos that give the stated gray photo, modulo 1000710007.

Examples3

  1. Example 1

    Input
    2 2
    0 0
    0 0
    
    Expected output
    10000
    
  2. Example 2

    Input
    2 1
    0
    1
    
    Expected output
    460
    
  3. Example 3

    Input
    1 3
    150 95 68
    
    Expected output
    561