Welcome to ZOJ
 Problem Sets Information Select Problem Runs Ranklist
ZOJ Problem Set - 3383
Shiro? Kuro?

Time Limit: 5 Seconds      Memory Limit: 65536 KB

Shikieiki Yamaxanadu (四季映姫・ヤマザナドゥ) is one of the gods that resides in hell and judges the deceased. She can clearly judge anything to be white (good) or black (evil). This ability allows her to get things settled once and for all. In her mind, only white or black is important, any other information about color is redundant.

A true-color bitmap should be converted to black-and-white bitmap. Firstly, the grayscale of a pixel is calculated using formala (11 * Red + 16 * Green + 5 * Blue) / 32. Secondly, the threshold is calculated using formala (192 + 2 * average_grayscale) / 3, where average_grayscale = sum_of_grayscale / (w * h). Lastly, convert pixels with grayscale less that threshold to black, and convert the others to white. All divisions are truncated divisions.

Input

There are multiple cases. Each case is a true-color bitmap. The first line is "wxh", then 3 ≤ h ≤ 300 lines, each contains 3 ≤ w ≤ 300 HTML colors. HTML colors are defined using a hex notation for the combination of Red, Green, and Blue color values. Hex values are written as 3 double digit numbers, starting with a # sign. The corresponding regex is m/^#[0-9A-F]{6}\$/.

Output

For each test case, output the black-and-white bitmap. Output blank for white and digit 9 for black.

Sample Input

```10x10
#1266E2 #03BF04 #B3988A #9B7411 #B3585E #BC036B #757E20 #9F37B7 #0150EF #AB34D4
#66B1D0 #631AD9 #24B176 #3933E7 #F731CF #BDFA8A #A88015 #7B07A0 #DDFD63 #EF5B6F
#BC80B6 #D10920 #3E4D65 #669217 #CC2C1D #9CF8A3 #669730 #667CC8 #A916C6 #611FFD
#7C8798 #C5A6A3 #8AB317 #EA177E #7372E2 #38BE40 #139C7A #213535 #71DA7B #AF5ACE
#7FBEB8 #401EC7 #2EE620 #E1C350 #B0653A #7F0F4D #852C00 #923573 #5995E5 #17837B
#8E7132 #69E6AE #70FCE4 #4C8941 #4832A5 #EF4C2B #7B4E38 #1E61A9 #3058C5 #3FA175
#B82C74 #DB3C4B #01D753 #83C951 #2047F6 #AD9F95 #75BAC9 #F87479 #133555 #82AEA9
#FF98A9 #819D40 #772A84 #8CEFD1 #8353DF #AC1654 #3A3130 #C0E192 #4E1EDC #3C4C6D
#664C29 #FD0067 #DC474A #6BFA6C #08339D #6416B3 #619AE7 #A28BF1 #23A668 #B0D211
#2A3E62 #1172AE #5340EB #FBFD76 #338D32 #99444D #6ED6CE #F055E0 #1F4E82 #32F0CA
38x26
#FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #3A3A3A #696969 #FAFAFA #AFAFAF #525252 #F1F1F1 #FEFEFE #959595 #9B9B9B #5A5A5A #2E2E2E #B7B7B7 #101010 #646464 #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF
#FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #EFEFEF #EAEAEA #656565 #ECECEC #DCDCDC #F5F5F5 #CBCBCB #979797 #747474 #383838 #D7D7D7 #454545 #BABABA #FEFEFE #A6A6A6 #6F6F6F #B4B4B4 #707070 #010101 #888888 #F9F9F9 #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF
#FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #4C4C4C #191919 #A7A7A7 #D7D7D7 #212121 #939393 #F2F2F2 #B5B5B5 #6C6C6C #9B9B9B #989898 #B1B1B1 #292929 #010101 #737373 #676767 #D3D3D3 #CCCCCC #E8E8E8 #EFEFEF #AFAFAF #2C2C2C #5D5D5D #AAAAAA #E9E9E9 #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF
#FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #848484 #B9B9B9 #767676 #8F8F8F #A6A6A6 #909090 #070707 #828282 #F2F2F2 #B5B5B5 #121212 #616161 #464646 #2D2D2D #6C6C6C #4C4C4C #9C9C9C #CBCBCB #FAFAFA #FFFFFF #D2D2D2 #C0C0C0 #1E1E1E #191919 #0D0D0D #404040 #F6F6F6 #F1F1F1 #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF
#FFFFFF #FFFFFF #FFFFFF #F2F2F2 #555555 #3B3B3B #C2C2C2 #707070 #F9F9F9 #474747 #E7E7E7 #FFFFFF #131313 #252525 #DBDBDB #4F4F4F #B8B8B8 #000000 #000000 #000000 #B1B1B1 #A8A8A8 #303030 #161616 #3A3A3A #2C2C2C #FFFFFF #FFFFFF #F7F7F7 #C6C6C6 #888888 #080808 #2C2C2C #424242 #4D4D4D #FFFFFF #FFFFFF #FFFFFF
#FFFFFF #FFFFFF #D8D8D8 #5C5C5C #CCCCCC #E6E6E6 #B8B8B8 #646464 #FFFFFF #FFFFFF #676767 #E6E6E6 #4F4F4F #000000 #4E4E4E #A3A3A3 #2A2A2A #171717 #6E6E6E #666666 #E9E9E9 #BBBBBB #BBBBBB #434343 #C4C4C4 #8B8B8B #2F2F2F #535353 #FFFFFF #FFFFFF #BDBDBD #C2C2C2 #616161 #E1E1E1 #666666 #0C0C0C #FFFFFF #FFFFFF
#FFFFFF #1A1A1A #C8C8C8 #939393 #A4A4A4 #1F1F1F #7C7C7C #FFFFFF #FFFFFF #D7D7D7 #565656 #777777 #000000 #A2A2A2 #545454 #A7A7A7 #222222 #ABABAB #FFFFFF #8F8F8F #4E4E4E #2D2D2D #A5A5A5 #B5B5B5 #ABABAB #D5D5D5 #9B9B9B #5B5B5B #0F0F0F #FFFFFF #FFFFFF #C3C3C3 #3C3C3C #3C3C3C #919191 #020202 #F7F7F7 #FFFFFF
#484848 #4E4E4E #080808 #8E8E8E #E7E7E7 #727272 #FFFFFF #FFFFFF #151515 #7C7C7C #0A0A0A #F2F2F2 #515151 #A9A9A9 #EAEAEA #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #444444 #3B3B3B #858585 #606060 #C1C1C1 #E4E4E4 #FFFFFF #FFFFFF #FFFFFF #5F5F5F #212121 #787878 #F5F5F5 #444444 #1A1A1A
#0D0D0D #1C1C1C #E8E8E8 #7C7C7C #282828 #EFEFEF #FFFFFF #FFFFFF #A9A9A9 #5A5A5A #E6E6E6 #888888 #838383 #656565 #D5D5D5 #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #010101 #B0B0B0 #464646 #878787 #FCFCFC #EDEDED #9A9A9A #FFFFFF #FFFFFF #E1E1E1 #171717 #111111 #9A9A9A #262626 #C1C1C1
#505050 #444444 #040404 #4F4F4F #080808 #FFFFFF #FFFFFF #FFFFFF #C3C3C3 #0F0F0F #F9F9F9 #8C8C8C #060606 #A3A3A3 #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FDFDFD #E6E6E6 #7B7B7B #3A3A3A #A6A6A6 #8C8C8C #0C0C0C #FFFFFF #FFFFFF #FFFFFF #1F1F1F #F7F7F7 #1D1D1D #4D4D4D #979797
#9F9F9F #BFBFBF #C4C4C4 #212121 #FFFFFF #FFFFFF #FFFFFF #FFFFFF #808080 #D2D2D2 #5A5A5A #5C5C5C #6C6C6C #C0C0C0 #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #313131 #C3C3C3 #626262 #090909 #4F4F4F #232323 #151515 #FFFFFF #FFFFFF #FFFFFF #EDEDED #F5F5F5 #5F5F5F #535353 #7D7D7D
#6C6C6C #555555 #F0F0F0 #242424 #FFFFFF #FFFFFF #FFFFFF #FFFFFF #000000 #414141 #525252 #919191 #212121 #A1A1A1 #A5A5A5 #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #4B4B4B #3B3B3B #F2F2F2 #000000 #010101 #434343 #C7C7C7 #FFFFFF #FFFFFF #FFFFFF #FFFFFF #999999 #FBFBFB #232323 #A8A8A8
#A7A7A7 #FFFFFF #858585 #9B9B9B #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FAFAFA #0B0B0B #B4B4B4 #191919 #212121 #E7E7E7 #7F7F7F #FCFCFC #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #414141 #636363 #0A0A0A #BFBFBF #000000 #000000 #595959 #BDBDBD #1F1F1F #FFFFFF #FFFFFF #FFFFFF #FFFFFF #2C2C2C #949494 #DCDCDC #A8A8A8
#585858 #F6F6F6 #010101 #D3D3D3 #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #4B4B4B #5D5D5D #050505 #676767 #000000 #1B1B1B #737373 #929292 #444444 #CFCFCF #0B0B0B #969696 #717171 #A0A0A0 #000000 #A3A3A3 #B8B8B8 #030303 #FEFEFE #0F0F0F #C4C4C4 #FFFFFF #FFFFFF #FFFFFF #FFFFFF #383838 #4C4C4C #F3F3F3 #686868
#F5F5F5 #E3E3E3 #5F5F5F #838383 #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #DCDCDC #494949 #585858 #0D0D0D #000000 #000000 #1D1D1D #616161 #797979 #000000 #282828 #C9C9C9 #7A7A7A #141414 #1A1A1A #CFCFCF #2E2E2E #1D1D1D #F4F4F4 #FFFFFF #FFFFFF #FFFFFF #FFFFFF #A4A4A4 #101010 #D5D5D5 #4B4B4B
#3C3C3C #595959 #5E5E5E #1F1F1F #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #BDBDBD #343434 #AAAAAA #8D8D8D #010101 #B6B6B6 #9C9C9C #C3C3C3 #9D9D9D #737373 #2E2E2E #9B9B9B #505050 #131313 #E8E8E8 #8E8E8E #7C7C7C #FFFFFF #FFFFFF #FFFFFF #F4F4F4 #989898 #E3E3E3 #F1F1F1 #B1B1B1
#A1A1A1 #B6B6B6 #4A4A4A #0D0D0D #646464 #FFFFFF #FFFFFF #FFFFFF #FFFFFF #4F4F4F #484848 #ADADAD #5D5D5D #797979 #FFFFFF #FFFFFF #7F7F7F #606060 #A9A9A9 #B7B7B7 #F0F0F0 #FFFFFF #FFFFFF #4C4C4C #292929 #C6C6C6 #C4C4C4 #A7A7A7 #DCDCDC #555555 #FFFFFF #FFFFFF #FFFFFF #585858 #282828 #CFCFCF #373737 #666666
#434343 #181818 #232323 #5A5A5A #878787 #FDFDFD #FFFFFF #FFFFFF #FFFFFF #101010 #EAEAEA #5E5E5E #5C5C5C #D5D5D5 #070707 #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #DCDCDC #737373 #A6A6A6 #131313 #9A9A9A #676767 #FFFFFF #FFFFFF #FFFFFF #DADADA #EBEBEB #E2E2E2 #6F6F6F #CFCFCF #3C3C3C
#0C0C0C #D9D9D9 #DCDCDC #262626 #C1C1C1 #020202 #FFFFFF #FFFFFF #FFFFFF #B5B5B5 #D4D4D4 #3C3C3C #000000 #212121 #565656 #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #282828 #070707 #959595 #ABABAB #3E3E3E #686868 #888888 #FFFFFF #FFFFFF #FFFFFF #C7C7C7 #F8F8F8 #CBCBCB #050505 #B3B3B3 #D3D3D3
#FFFFFF #4B4B4B #888888 #5C5C5C #CCCCCC #2E2E2E #646464 #FFFFFF #FFFFFF #ACACAC #0D0D0D #BEBEBE #000000 #535353 #191919 #2A2A2A #858585 #090909 #1B1B1B #979797 #CFCFCF #313131 #C6C6C6 #D6D6D6 #000000 #A7A7A7 #ECECEC #3E3E3E #FFFFFF #FFFFFF #FFFFFF #242424 #434343 #FCFCFC #878787 #A9A9A9 #7F7F7F #FFFFFF
#FFFFFF #DDDDDD #0B0B0B #000000 #494949 #F8F8F8 #C3C3C3 #D5D5D5 #FFFFFF #FFFFFF #797979 #BCBCBC #787878 #C6C6C6 #000000 #030303 #838383 #1B1B1B #616161 #DCDCDC #080808 #A5A5A5 #000000 #7D7D7D #707070 #2C2C2C #D1D1D1 #E0E0E0 #FFFFFF #FFFFFF #353535 #373737 #2D2D2D #0B0B0B #D8D8D8 #4D4D4D #FFFFFF #FFFFFF
#FFFFFF #FFFFFF #FFFFFF #585858 #CFCFCF #424242 #3F3F3F #777777 #FDFDFD #A2A2A2 #FFFFFF #FFFFFF #878787 #232323 #BDBDBD #343434 #787878 #BABABA #F1F1F1 #404040 #D9D9D9 #535353 #808080 #9E9E9E #060606 #565656 #FFFFFF #FFFFFF #6D6D6D #020202 #CBCBCB #FAFAFA #4A4A4A #D0D0D0 #242424 #FFFFFF #FFFFFF #FFFFFF
#FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #4A4A4A #888888 #DFDFDF #EEEEEE #F9F9F9 #A8A8A8 #777777 #FFFFFF #FFFFFF #666666 #F0F0F0 #363636 #4A4A4A #030303 #DBDBDB #9B9B9B #636363 #232323 #FFFFFF #FFFFFF #FFFFFF #767676 #EAEAEA #1E1E1E #1D1D1D #C3C3C3 #3E3E3E #808080 #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF
#FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #4B4B4B #0D0D0D #3E3E3E #D0D0D0 #303030 #707070 #333333 #2E2E2E #A6A6A6 #E9E9E9 #676767 #838383 #484848 #F3F3F3 #7E7E7E #202020 #B9B9B9 #161616 #5A5A5A #505050 #FDFDFD #080808 #EDEDED #1F1F1F #585858 #F1F1F1 #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF
#FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #646464 #B7B7B7 #BEBEBE #090909 #191919 #252525 #484848 #0F0F0F #999999 #D0D0D0 #020202 #A6A6A6 #333333 #323232 #3C3C3C #121212 #7B7B7B #E5E5E5 #B5B5B5 #A8A8A8 #EBEBEB #F0F0F0 #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF
#FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #D7D7D7 #DBDBDB #D0D0D0 #7A7A7A #4B4B4B #151515 #3C3C3C #9A9A9A #FEFEFE #4E4E4E #9D9D9D #535353 #D1D1D1 #EAEAEA #020202 #1B1B1B #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF #FFFFFF
```

Sample Output

```10x10
9 9   9 9 9 9 9 9 9
9 9 9 9   9 9
9 9 9 9   9 9 9 9
9   9 9 9 9 9 9   9
9 9   9 9 9 9 9 9
9     9 9 9 9 9 9 9
9 9 9   9       9
9 9   9 9 9   9 9
9 9 9   9 9     9
9 9 9   9 9     9
38x26
9 9     9     9 9 9 9   9 9
9         9 9 9   9     9 9   9 9 9
9 9 9   9 9     9 9 9   9 9 9 9           9 9 9
9   9 9 9 9 9 9     9 9 9 9 9 9 9           9 9 9 9
9 9   9   9     9 9   9   9 9 9   9 9 9 9 9         9 9 9 9 9
9       9     9   9 9 9 9 9 9 9 9       9   9 9 9         9   9 9
9   9 9 9 9       9 9 9 9 9 9 9 9   9 9 9 9   9   9 9 9       9 9 9 9
9 9 9 9   9     9 9 9   9 9                   9 9 9 9           9 9 9   9 9
9 9   9 9       9 9   9 9 9                   9   9 9     9       9 9 9 9
9 9 9 9 9         9   9 9 9                       9 9 9 9 9       9   9 9 9
9     9         9   9 9 9                     9   9 9 9 9 9           9 9 9
9 9   9         9 9 9 9 9 9 9                 9 9   9 9 9           9   9 9
9   9 9           9   9 9   9             9 9 9   9 9 9   9         9 9   9
9   9             9 9 9 9 9 9 9 9 9   9 9 9 9 9 9   9   9           9 9   9
9 9                 9 9 9 9 9 9 9 9 9 9   9 9 9   9 9           9 9   9
9 9 9 9                     9 9 9 9   9   9 9 9 9 9 9   9 9         9
9   9 9 9         9 9 9 9 9     9 9 9         9 9     9   9       9 9   9 9
9 9 9 9 9         9   9 9   9                   9 9 9 9 9             9   9
9     9   9           9 9 9 9               9 9 9 9 9 9 9             9
9 9 9   9 9     9 9   9 9 9 9 9 9 9 9   9     9 9   9       9 9   9 9 9
9 9 9           9   9   9 9 9 9 9   9 9 9 9 9 9         9 9 9 9   9
9   9 9 9   9     9 9   9 9     9   9 9 9 9 9     9 9     9   9
9 9       9 9     9   9 9 9   9 9 9       9   9 9   9 9
9 9 9   9 9 9 9 9   9 9 9   9 9   9 9 9   9   9 9
9     9 9 9 9 9 9   9 9 9 9 9 9 9     9
9 9 9 9 9   9 9 9     9 9
```

References

Author: WU, Zejun
Source: ACM × Touhou
Contest: ZOJ Monthly, August 2010
Submit    Status