Problem:
 Score : 500 points    Problem Statement You are given two integers A and B .  Print a grid where each square is painted white or black that satisfies the following conditions, in the format specified in Output section:   Let the size of the grid be h \times w ( h vertical, w horizontal). Both h and w are at most 100 .  The set of the squares painted white is divided into exactly A connected components.  The set of the squares painted black is divided into exactly B connected components.   It can be proved that there always exist one or more solutions under the conditions specified in Constraints section.
If there are multiple solutions, any of them may be printed.      Notes Two squares painted white, c_1 and c_2 , are called connected when the square c_2 can be reached from the square c_1 passing only white squares by repeatedly moving up, down, left or right to an adjacent square.  A set of squares painted white, S , forms a connected component when the following conditions are met:   Any two squares in S are connected.  No pair of a square painted white that is not included in S and a square included in S is connected.   A connected component of squares painted black is defined similarly.      Constraints  1 \leq A \leq 500  1 \leq B \leq 500         Input Input is given from Standard Input in the following format:  A  B       Output Output should be in the following format:   In the first line, print integers h and w representing the size of the grid you constructed, with a space in between.  Then, print h more lines. The i -th ( 1 \leq i \leq h ) of these lines should contain a string s_i as follows:  If the square at the i -th row and j -th column ( 1 \leq j \leq w ) in the grid is painted white, the j -th character in s_i should be . .  If the square at the i -th row and j -th column ( 1 \leq j \leq w ) in the grid is painted black, the j -th character in s_i should be # .           Sample Input 1 2 3      Sample Output 1 3 3
##.
..#
#.#  This output corresponds to the grid below:          Sample Input 2 7 8      Sample Output 2 3 5
#.#.#
.#.#.
#.#.#       Sample Input 3 1 1      Sample Output 3 4 2
..
#.
##
##       Sample Input 4 3 14      Sample Output 4 8 18
..................
..................
....##.......####.
....#.#.....#.....
...#...#....#.....
..#.###.#...#.....
.#.......#..#.....
#.........#..####.

Solution (Python):
A, B = map(int, input().split())
white = [["
black = [["."] * 100 for i in range(50)]
A, B = A-1, B-1

row = 0
line = 0
for i in range(A):
    white[line][row] = "."
    row += 2
    if row >= 100:
        row = 0
        line += 2

row = 0
line = 1
for i in range(B):
    black[line][row] = "
    row += 2
    if row >= 100:
        row = 0
        line += 2

ans = white + black
print(100, 100)
for a in ans:
    print("".join(a))

Solution (Python):
a, b = map(lambda x: int(x) - 1, raw_input().split())
x = [['.'] * 100 for _ in xrange(100)]
for i in xrange(50, 100):
    for j in xrange(100):
        x[i][j] = '
for i in xrange(0, 50, 2):
    if b:
        for j in xrange(0, 100, 2):
            if b:
                x[i][j] = '
                b -= 1
for i in xrange(99, 49, -2):
    if a:
        for j in xrange(0, 100, 2):
            if a:
                x[i][j] = '.'
                a -= 1
print '\n'.join(['100 100'] + [''.join(_) for _ in x])

Solution (Python):
def print_component(a, b, n):
    for _ in range(25):
        print(a * 100)
        if n:
            x = min(n, 50)
            n -= x
            print((a+b)*x + a*2*(50-x))
        else:
            print(a * 100)


A, B = map(int, input().split())

print('100 100')
print_component('
print_component('.', '

Solution (Python):
from random import*
seed()
dd = ((-1, 0), (-1, -1), (0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, 1))
def make(C, rest, r=randint):
    p, q = C
    M = [[p]*100 for i in range(50)]
    while rest:
        x = r(1, 98)
        y = r(1, 48)
        if M[y][x] == q:
            continue
        for dx, dy in dd:
            if M[y+dy][x+dx] == q:
                break
        else:
            M[y][x] = q
            rest -= 1
    return map("".join, M)
A, B = map(int, input().split())
print(100, 100)
print(*make(".
print(*make("

Solution (Python):
A,B = map(int,input().split())
H,W = 100,100

grid = [['

A -= 1
for h in range(1,50,2):
	for w in range(1, W, 2):
		if A > 0:
			grid[h][w] = '.'
			A -= 1
		else:
			break
B -= 1
for h in range(51, 100, 2):
	for w in range(1, W, 2):
		if B > 0:
			grid[h][w] = '
			B -= 1
		else:
			break

print(H,W)
for h in range(H):
	print("".join(grid[h][:]))

Solution (Python):
p,h,l,s,w,b,r=print,80,40,list,'.','
W,B=map(int,input().split())
m=s(map(s,zip(*[iter(w*h*l+b*h*l)]*h)))
for i in r(B-1):m[i//l*2][i%l*2]=b
for i in r(W-1):m[79-i//l*2][79-i%l*2]=w
p(h,h)
[p(''.join(l)) for l in m]

Solution (Python):
def d_grid_components(A, B):  
    H, W = 100, 100  
    
    grid = [['
    
    white = A - 1
    for h in range(1, 50, 2):
        for w in range(1, W, 2):
            if white > 0:
                grid[h][w] = '.'
                white -= 1
            else:
                break
        else:
            continue
        break
    
    black = B - 1
    for h in range(51, 100, 2):
        for w in range(1, W, 2):
            if black > 0:
                grid[h][w] = '
                black -= 1
            else:
                break
        else:
            continue
        break
    ans = '100 100\n'
    for h in range(H):
        ans += ''.join(grid[h][:]) + '\n'
    return ans[:-1]
A,B = [int(i) for i in input().split()]
print(d_grid_components(A, B))

Solution (Python):
def main():
    """
    0? <= h, w <= 100
        grid
    1 <= A, B <= 500

    2つの白く塗られたマス c1,c2が連結であるとは、
        マスc1からマスc2へ、
        上下左右に隣り合うマスへの移動を繰り返して、
        白く塗られたマスだけを通って移動できること

    白く塗られたマスの集合 S が連結成分であるとは、
        S のどの2 つのマスも連結である
        S に含まれないどの白く塗られたマスと、Sに含まれるどのマスも連結ではない
    """
    A, B = map(int, input().split())

    f(A, B)


def f(A, B):
    """
    解説pdfがないので、Twitter/動画を参考
    市松模様が浮かんでた
    白い海、黒い海をつくり
    白に黒の島を浮かべ、黒に白の島を浮かべるイメージらしい
    これに至る発想の流れの解説がない…発想力
        100*100だったので,最小領域で考えず最大領域を作ることはしたかった
        1マスは連結だった…
    """
    wh = "."
    bl = "

    grid = [
        list(wh * 50 + bl * 50)
        for _ in range(100)
    ]
    update(A, grid, wh, shift=50)
    update(B, grid, bl, shift=0)

    print(100, 100)
    for line in grid:
        print(*line, sep="")


def update(n, grid, mark, shift):
    rest = n - 1
    for i in range(0, 100, 2):
        for j in range(1+shift, shift+49, 2):
            if rest <= 0:
                return
            grid[i][j] = mark
            rest -= 1


if __name__ == '__main__':
    main()

Solution (Python):
p,h,l,s,w,b,r=print,80,40,list,'.','
W,B=map(int,input().split())
m=s(map(s,zip(*[iter(w*h*l+b*h*l)]*h)))
for i in r(B-1):m[i//l*2][i%l*2]=b
for i in r(W-1):m[79-i//l*2][79-i%l*2]=w
p(h,h)
[p(''.join(l)) for l in m]

Solution (Python):
A,B = [int(i) for i in input().split()]
ans = []
for _ in range(50):
    ans.append(["."]*100)
for _ in range(50):
    ans.append(["

for i in range(B-1):
    ans[2*int(i/50)][2*(i%50)] = "
for j in range(A-1):
    ans[-1-2*int(j/50)][2*(j%50)] = "."
print("100 100")
for po in ans:
    print(*po,sep="")

Solution (Python):
p,h,l,s,w,b=print,80,40,list,'.','
W,B=s(map(int,input().split()))
ret=s(map(list,zip(*[iter(w*h*l+b*h*l)]*h)))

for bidx in range(B-1):
 ret[bidx//l*2][bidx%l*2]=b

for widx in range(W-1):
 ret[79-widx//l*2][79-widx%l*2]=w

p(h,h)
[p(''.join(line)) for line in ret]

Solution (Python):
A, B = map(int, input().split())

if A <= B:
    mincolor = "."
    maxcolor = "
    minnum = A
    maxnum = B
else:
    mincolor = "
    maxcolor = "."
    minnum = B
    maxnum = A
gridmap = []
for i in range(100):
    gridmap.append([mincolor]*100)
for i in range(1,100,2):
    for j in range(1,98,2):
        gridmap[i][j] = maxcolor
        maxnum -= 1
        if maxnum == 0:
            break
    if maxnum == 0:
        break

for k in range(0,100,2):
    for l in range(0,98,2):
        if minnum == 1:
            break
        gridmap[k][l+1], gridmap[k+1][l] = maxcolor, maxcolor
        minnum -= 1
        gridmap[i][j] = maxcolor
        if j == 97:
            j = 1
            i += 2
        else:
            j += 2
    if minnum == 1:
        break

print(100,100)
for i in range(100):
    ans = ""
    for j in range(100):
        ans += gridmap[i][j]
    print(ans)

Solution (Python):


tmp = map(int, raw_input().split())

A = tmp[0]
B = tmp[1]

board = []
for i in range(100):
    tmp = []
    for j in range(100):
        if j < 50:
            tmp.append(0)
        else:
            tmp.append(1)
    board.append(tmp)

rest_0 = A - 1
rest_1 = B - 1

flag1 = False
flag2 = False

for i in range(0, 100, 2):
    for j in range(0, 48, 2):
        if rest_1 > 0:
            board[i][j] = 1
            rest_1 -= 1
            if rest_1 == 0:
                flag1 = True


        if rest_0 > 0:
            board[i][50 + j + 2] = 0
            rest_0 -= 1
            if rest_0 == 0:
                flag2 = True

    if flag1 and flag2:
        break

print str(100) + " " + str(100)

for i in range(100):
    output_list = []
    for j in range(100):
        if board[i][j] == 0:
            output_list.append(".")
        else:
            output_list.append("
    output = "".join(output_list)
    print output

Solution (Python):
A,B=map(int,input().split())
M=[[] for x in range(100)]
M[0]=[str('.') for i in range(100)]
for i in range(1,99):
  if i%2==1:
    M[i]=['.']+[str('
  else:
    M[i]=[str('.') for a in range(99)]+['
M[99]=[str('

ch=0
for i in range(49):
  if B==1:
    break
  for j in range(1,49):
    if B==1:
      break
    M[i*2+1][j*2+1]='.'
    B-=1
for i in range(49):
  if A==1:
    break
  for j in range(1,49):
    if A==1:
      break
    M[99-(2*i+1)][j*2+1]='
    A-=1
print(100,100)
for i in range(100):
  ans=''.join(M[i])
  print(ans)

Solution (Python):
def factoring(n):
    for i in range(100, 0, -1):
        if n%i == 0:
            return i
    return n

def is_sq(n):
    for i in range(1,100):
        if i**2 == n:
            return True
    return False

def make_ichimatsu(n):
    height = factoring(n)
    width = n // height
    if width%2:
        width, height = height, width
    ret = []
    for h in range(height):
        line = '
        line = line[h%2:] + line[:h%2]
        ret.append(line)
    return (height, width, ret)

def make_oddichimatsu(w,b):
    width = height = factoring(w+b)
    ret = '.' * (w>b) + '
    ret = list(map(''.join, zip(*[iter(ret)]*height)))
    return (height, width, ret)



def calc(W, B):
    if W==B and factoring(W+B)<W+B:
        return make_ichimatsu(W+B)

def main():
    W, B = list(map(int, input().split()))

    
    ret = '.'*100*50 + '
    ret = list(map(list, zip(*[iter(ret)]*100)))

    
    for bidx in range(B-1):
        ret[(bidx//50)*2][(bidx%50)*2] = '
    
    
    for widx in range(W-1):
        ret[99-(widx//50)*2][99-(widx%50)*2] = '.'

    print('{} {}'.format(100, 100))
    for line in ret:
        print(''.join(line))

if __name__ == '__main__':
    main()

Solution (Python):
A, B = [int(_) for _ in input().split()]

patA, patB = "

if A > B:
    A, B = B, A
    patA, patB = patB, patA

h, w = 80, 100

rows = [[patB] * w for _ in range(h)]

for i in range(B):
    x = i % (w // 4) * 4
    y = i // (w // 4) * 4
    rows[y][x:x+3] = patA, patA, patA
    rows[y+1][x:x+3] = patA, patA, patA
    rows[y+2][x:x+3] = patA, patA, patA
    if i < A - 1:
        rows[y+1][x+1] = patB

print(h, w)
for row in rows:
    print("".join(row))

Solution (Python):
A, B = list(map(int, input().split()))
M = max(A, B)
if M == 1:
    print(1, 2)
    print("

else:
    D = 2 * (M - 1) if M <= 50 else 100
    if A == 1:
        h = ((B-2)//50 + 2) * 2  + 1
    elif B == 1:
        h = ((A-2)//50 + 2) * 2  + 1 
    else:
        h = ((A-2)//50 + (B-2)//50 + 2) * 2  + 1 

    print(h, D)
    
    def gene(N, flag):
        global h
        N -= 1
        p, q = [".", "
        pq = p + q
        count = (N-1)//50 + 1
        while count > 1:
            print(pq * 50)
            print(q * 100)
            count -= 1
            N -= 50
            
        print(pq * N + q * (D - 2*N))
        print(q * D)
    
    gene(A, "A")
    print("." * D)
    gene(B, "B")

Solution (Python):
a, b = map(int, input().split())
z = True
y = 0
s = ''
while a >= 50:
	x = 100
	s += '
	s += '
	y += 2
	a -= 49
s += '.
s += '
s += '.' * 100 + '\n'
y += 3
b -= 1
while b >= 50:
	x = 100
	s += '
	s += '.' * 100 + '\n'
	y += 2
	b -= 50
s += '
y += 1
print(y, 100)
print(s)

Solution (Python):
import math

A, B = map(int, input().split())

A_row = math.ceil((A-1)/50)
A_row_full = (A-1)//50
B_row = math.ceil((B-1)/50)
B_row_full = (B-1)//50

if A_row == 0:
    A_row = 1
if B_row == 0:
    B_row = 1

A_mod = (A-1)%50
B_mod = (B-1)%50

if A_row == A_row_full:
    A_mod = 50
    A_row_full -= 1
if B_row == B_row_full:
    B_mod = 50
    B_row_full -= 1

print("100 ", (A_row+B_row)*2)

for i in range(50):
    print('.
    print('

Solution (Python):
import math

A, B = map(int, input().split())

A_row = math.ceil((A-1)/50)
if A_row == 0:
    A_row = 1
A_row_full = (A-1)//50
B_row = math.ceil((B-1)/50)
if B_row == 0:
    B_row = 1
B_row_full = (B-1)//50

print("100 ", (A_row+B_row)*2)

A_mod = (A-1)%50
B_mod = (B-1)%50

if A_row == A_row_full:
    A_add = ''
    A_add2 = ''
else:
    A_add = '.
    A_add2 = '

if B_row == B_row_full:
    B_add = ''
    B_add2 = ''
else:
    B_add = '.
    B_add2 = '..'


for i in range(50):
    print('.
    print('

Solution (Python):
a, b = map(int, raw_input().strip().split())

h, w = 100, 100
lines = []

orig_a = a

while a > 50:
    lines.append(list(".
    lines.append(list("
    a -= 50

if a > 1:
    left = ".
    right = "
    lines.append(list(left + right))
    lines.append(list("

while len(lines) < 100:
    lines.append(list("." * 100))

if orig_a != 1:
    b -= 1
cl = 99

while b > 49:
    for i in xrange(50):
        lines[cl][2 * i] = "
    b -= 50
    cl -= 2

if b > 0:
    for i in xrange(b):
        lines[cl][2 * i] = "

print h, w
for line in lines:
    print "".join(line)

Solution (Python):
import sys

a,b=map(int,input().split())
if(a>=b):
    manyC="."
    fewC="
    many=a
    few=b
else:
    many=b
    few=a
    manyC="
    fewC="."
h,w=97,97
outp=[[(fewC)for j in range(w)]for i in range(h)]
for i in range(many):
    if((i//25)==0):y=0
    elif((i//25)==1):y=3
    else:y=4*(i//25)-1
    if((i%25)==0):x=1
    elif((i%25)==1):x=3
    else:x=4*(i%25)-1
    outp[y][x]=manyC
for j in range(few-1):
    if(j==0):
        outp[1][0]=manyC
        outp[1][1]=manyC
    elif(j//25==0):
        x=j*4-1
        outp[1][x]=manyC
        outp[1][x+1]=manyC
        if(j!=24):
            outp[1][x+2]=manyC
            outp[0][x+2]=manyC
    else:
        y=4*(j//25)-1
        if(j%25==0):
            outp[y][0]=manyC
            outp[y+1][1]=manyC
            outp[y+2][1]=manyC
            outp[y+2][0]=manyC
        else:
            x=4*(j%25)-1
            outp[y][x+1]=manyC
            outp[y+1][x]=manyC
            outp[y+2][x]=manyC
            outp[y+2][x+1]=manyC
            if((j%25)!=24):
                outp[y][x+2]=manyC
                outp[y+1][x+2]=manyC
                outp[y+2][x+2]=manyC
print(h,w)
for i in range(h):
    print("".join(outp[i]))

Solution (Python):
import math
b, a = map(int, input().strip().split(" "))
h = 2 * math.ceil(max((a - 1) / 25, (b - 1) / 25)) + 1
a -= 1
b -= 1
print("{} {}".format(h, 100))
for i in range(h):
    if i % 2 == 0:
        print("." * 50 + "
    else:
        if a > 0 and b > 0:
            ma = min(a, 25)
            mb = min(b, 25)
            print("
            a -= ma
            b -= mb
        elif a == 0 and b > 0:
            mb = min(b, 25)
            print("." * 50 + "
            b -= mb
        elif a > 0 and b == 0:
            ma = min(a, 25)
            print("
            a -= ma

Solution (Python):
W, B = map(int, input().split())

WHITE = "."
BLACK = "

base_row = (B // 50 + 1) * 2
GRID = [[WHITE if row < base_row else BLACK for _ in range(100)] for row in range(100)]

for i in range(B - 1):
    GRID[2 * (i // 50)][(i % 50) * 2] = BLACK

for i in range(W - 1):
    GRID[2 * (i // 50) + base_row + 1][(i % 50) * 2] = WHITE

print("100 100")
for row in GRID:
    for c in row:
        print(c, end='')
    print()

Solution (Python):
a, b = list(map(int, input().split()))

white = "."
black = "
wb = white+black
wremaining = a - 1
bremaining = b - 1

print("100 100")
for i in range(25):
    if bremaining >= 50:
        print(wb*50)
        bremaining -=50
    elif bremaining > 0:
        s = wb*bremaining + white*(50-bremaining)*2
        print(s)
        bremaining = 0
    else:
        print(white*100)
    print(white*100)

for i in range(25):
    print(black*100)
    if wremaining >= 50:
        print(wb*50)
        wremaining -= 50
    elif wremaining > 0:
        s = wb*wremaining + black*(50-wremaining)*2
        print(s)
        wremaining = 0
    else:
        print(black*100)

Solution (Python):
A, B = [int(_) for _ in input().split()]


pat = "

if A > B:
    A, B = B, A
    pat = pat[1] + pat[0]

h, w = 100, 100

rows = [[1] * w for _ in range(h)]

i = 0
x = 0
y = 3
while i < B:
    rows[y][x] = 0
    rows[y][x + 1] = 0
    rows[y][x + 2] = 0
    x += 4
    if x >= w:
        x = 0
        y += 4
    i += 1

i = 1
x = 0
y = 1
while i < A:
    rows[y][x] = 0
    rows[y][x + 1] = 0
    rows[y][x + 2] = 0
    rows[y + 1][x] = 0
    rows[y + 1][x + 2] = 0
    x += 4
    if x >= w:
        x = 0
        y += 4
    i += 1

print(h, w)
for y, row in enumerate(rows):
    print("".join(pat[c] for c in row))

Solution (Python):


a, b = map(int, input().split())

h = 98
w = 99
print(h, w)

grid = [["." for i in range(w)] for j in range(h)]

for i in range(h // 2, h):
    for j in range(w):
        grid[i][j] = "

def ij_k(k):
    row = (w - 1) // 2
    i = (k // row) * 2 + 1
    j = (k % row) * 2 + 1
    assert 0 < i < h // 2 - 1
    assert 0 < j < w - 1
    return i, j

for k in range(b - 1):
    i, j = ij_k(k)
    grid[i][j] = "

for k in range(a - 1):
    i, j = ij_k(k)
    grid[i + h // 2][j] = "."

for i in range(h):
    r = "".join(grid[i])
    print(r)