This page is still under construction.

Parts of this page are still being built. What you see may change.

Black and White Panel

Time limit2sMemory limit256 MB

Summary
Print the fixed 101-column black and white grid whose isolated single tiles yield exactly b black areas and w white areas.
Level

Easy2 of 10

Topics
Implementation, Matrix
Solved
No attempts yet

Problem

You build a rectangular panel out of black and white square tiles of the same size. The finished panel must contain exactly bb 4-connected areas of black tiles and exactly ww 4-connected areas of white tiles.

A 4-connected area of one color is a maximal set of tiles that satisfies both conditions below.

  • All tiles of the set have the same color.
  • For any two tiles of the set there is a sequence of tiles of the set connecting them, and consecutive tiles of the sequence share a side.

Many panels meet these counts, so only the panel fixed by the output rule below is accepted.

Input

The first line contains the number of black areas bb and the number of white areas ww. (1≤b,w≤10001 \le b, w \le 1000)

Output

Print the number of rows rr and the number of columns cc of the panel on the first line, then print rr lines of cc characters each. A black tile is @ and a white tile is ..

The accepted panel is fixed by the rule below. Rows and columns are numbered from 1.

  • Let p=w−1p = w - 1 and q=b−1q = b - 1.
  • The panel always has c=101c = 101 columns.
  • The top black block has height h1=2⌈p/50⌉+1h_1 = 2\lceil p/50 \rceil + 1, the bottom white block has height h2=2⌈q/50⌉+1h_2 = 2\lceil q/50 \rceil + 1, and r=h1+h2r = h_1 + h_2.
  • Rows 11 through h1h_1 form the top block and start out all @. For each i=1,2,…,pi = 1, 2, \dots, p, change the tile in row 2⌈i/50⌉2\lceil i/50 \rceil and column 2(((i−1) mod 50)+1)2(((i-1) \bmod 50) + 1) to ..
  • Rows h1+1h_1 + 1 through rr form the bottom block and start out all .. For each j=1,2,…,qj = 1, 2, \dots, q, change the tile in row h1+2⌈j/50⌉h_1 + 2\lceil j/50 \rceil and column 2(((j−1) mod 50)+1)2(((j-1) \bmod 50) + 1) to @.

Examples4

  1. Example 1

    Input
    2 3
    
    Expected output
    6 101
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @.@.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    .....................................................................................................
    .@...................................................................................................
    .....................................................................................................
    
  2. Example 2

    Input
    1 1
    
    Expected output
    2 101
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    .....................................................................................................
    
  3. Example 3

    Input
    1 2
    
    Expected output
    4 101
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    .....................................................................................................
    
  4. Example 4

    Input
    2 1
    
    Expected output
    4 101
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    .....................................................................................................
    .@...................................................................................................
    .....................................................................................................