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):



def get_next_int():
    return int(float(input()))


def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])


def get_next_str():
    return input()


def get_next_strs(delim=" "):
    return tuple(input().split(delim))


def get_next_by_types(*value_types, delim=" "):
    return tuple([t(x) for t, x in zip(value_types, input().split(delim))])


def solve():
    A, B = get_next_ints()
    K = 2
    while K * 2 * K / 4 < max(A, B):
        K *= 2
    grid = [["
    grid.extend([["."] * 2 * K for i in range(K)])
    

    x, y = 0, 0
    while A > 1:
        grid[y][x] = "."
        if x + 2 >= 2 * K:
            y += 2
            x = 0
        else:
            x += 2
        A -= 1
    x, y = 2 * K - 1, 2 * K - 1
    while B > 1:
        grid[y][x] = "
        if x - 2 < 0:
            y -= 2
            x = 2 * K - 1
        else:
            x -= 2
        B -= 1
    print(2 * K, 2 * K)
    for row in grid:
        print(''.join(row))
solve()

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

s1 = "
.
s2 = "....................................................................................................\n\

black = '
white = '.' * 100 + '\n'

cnt = (A-1) // 50
mer = (A - 1) % 50
if mer == 0:
	up = s1 * cnt + black
else:
	up = s1 * cnt + black + ('.

cnt = (B-1) // 50
mer = (B - 1) % 50

if mer == 0:
	down = s2 * cnt + white
else:
	down = s2 * cnt + white + ('

print(str(len((up+down)) // 100) + " 100")
print(up + down)

Solution (Python):
a, b = map(int, input().split())
w = 100
grid = []
grid.append('.'*w)
a -= 1
while b > 1:
    x = min(w//2, b-1)
    b -= x
    grid.append('
    grid.append('.'*w)
grid.append('
b -= 1
while a > 0:
    x = min(w//2, a)
    a -= x
    grid.append('
    grid.append('
print(len(grid), w)
for row in grid:
    print(row)

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

bd = []
for i in range(32):
    bd.append(['
for i in range(32):
    bd.append(['.' for _ in range(64)])

for i in range(a - 1):
    bd[(i // 32) * 2][(i % 32) * 2] = '.'

for i in range(b - 1):
    bd[63 - (i // 32) * 2][63 - (i % 32) * 2] = '

print("64 64")
for i in range(64):
    print(''.join(bd[i]))

Solution (Python):

def inpl(): return list(map(int, input().split()))
"""
1 <= A, B <= 1659まで対応してるよ
"""
A, B = inpl()

L = [["."]*50 for i in range(100)]
R = [["

def plot(R):
    print("\n".join(["".join(r) for r in R]))

count = 0
for i in range(98):
    for j in range(16):
        if count == B-1:
            break
        L[i+1][j*3 + i%3 + 1] = "
        count += 1

count = 0
for i in range(98):
    for j in range(16):
        if count == A-1:
            break
        R[i+1][j*3 + i%3 + 1] = "."
        count += 1
        
ANS = [l+r for l, r in zip(L, R)]

print(100, 100)
plot(ANS)

Solution (Python):
A,B = map(int,input().split())
n = 50
m = n*2

grid = []
for i in range(n):
    grid.append(['.'] * m)
for i in range(n):
    grid.append(['

x = 0
y = 0
for i in range(B-1):
    grid[y][x] = '
    x += 2
    if x >= m:
        x -= m
        y += 2

x = 0
y = n+1
for i in range(A-1):
    grid[y][x] = '.'
    x += 2
    if x >= m:
        x -= m
        y += 2

print(str(m) + ' ' + str(m))
for row in grid:
    print(''.join(row))

Solution (Python):
m = []
for i in range(100):
	m.append([])
	for j in range(100):
		m[i].append('.' if (i//50 > 0) else '
a,b = map(int,input().split())
for i in range(1,a):
	x = (i // 50)*2
	y = (i % 50)*2
	m[x][y] = '.'
for i in range(1,b):
	x = 99 - (i // 50)*2
	y = 99 - (i % 50)*2
	m[x][y] = '
print("100 100")
for i in range(100):
	print(''.join(m[i]))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    a,b = LI()
    r = [['.']*50+['
    a -= 1
    b -= 1
    for i in range(0,100,2):
        for j in range(0,40,2):
            if b < 1:
                break
            r[i][j] = '
            b -= 1
        for j in range(60,100,2):
            if a < 1:
                break
            r[i][j] = '.'
            a -= 1



    return '100 100\n' + '\n'.join(map(lambda x: ''.join(x),r))


print(main())

Solution (Python):
from math import ceil

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

W = 52
R1 = ceil((A - 1) / ((W - 2) // 2))
R2 = ceil((B - 1) / (W // 2))
H = 1 + R1 * 2 + R2 * 2
print(H, W)

print('

A -= 1
for i in range(R1):
    num = min(max(A, 0), (W - 2) // 2)
    print('
    print('
    A -= (W - 2) // 2

B -= 1
for i in range(R2):
    num = min(max(B, 0), W // 2)
    print('.' * W)
    print('
    B -= W // 2

Solution (Python):
a,b=map(int,input().split())
print(40,100)
rows=['
rows[0]='
for i in range((a-1)//50):
  rows[2*i+2]='
rows[21]='
for i in range((b-1)//50):
  rows[2*i+23]='
print('\n'.join(rows))

Solution (Python):
def main():
    a, b = map(int, input().split())
    s, k = '.
    ans = [[k] * 100 for _ in range(50)] + [[s] * 100 for _ in range(50)]
    col = 0
    row = 0
    for _ in range(a - 1):
        ans[row][col] = s
        col += 2
        if col == 100:
            col = 0
            row += 2
    col = 0
    row = 99
    for _ in range(b - 1):
        ans[row][col] = k
        col += 2
        if col == 100:
            col = 0
            row -= 2
    print(100, 100)
    for row in ans:
        print(''.join(row))


if __name__ == '__main__':
    main()

Solution (Python):


import math


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

    A, B = B, A

    if A == B == 1:
        print(1, 2)
        print('.
        return

    N = 50 if max(A, B) >= 50 else max(A, B)

    ans = []
    if A != 1:
        if B != 1:
            a = A - 1
        else:
            a = A
        while a > 0:
            tmp = []
            for i in range(N):
                if a <= 0:
                    tmp.append('..')
                else:
                    
                    tmp.append('
                    a -= 1
            ans.append(''.join(tmp))
            ans.append('.' * N * 2)
    if B != 1:
        if A != 1:
            b = B - 1
        else:
            b = B
        ans.append('
        while b > 0:
            tmp = []
            for i in range(N):
                if b <= 0:
                    tmp.append('
                else:
                    tmp.append('.
                    b -= 1
            ans.append(''.join(tmp))
            ans.append('
    print(len(ans), len(ans[0]))
    for l in ans:
        print(l)


if __name__ == '__main__':
    
    main()

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

print(100, 100)
big = max(A, B)
small = min(A, B)

ans = ['

b = 1
s = 1
flag = True
for i in range(98):
  if s + 50 <= small:
    ans.append(['
    b += 50
    s += 50
  elif s < small < s + 50:
    l = small - s
    ans.append(['
    flag = True
    b += l
    s += l
  elif flag:
    ans.append('.'*100)
    flag = False
  else:
    if b + 50 <= big:
      ans.append('
      b += 50
    elif b < big < b + 50:
      l = big - b
      ans.append('
      b += l
    else:
      ans.append('.'*100)
    flag = True

for i in range(100):
  if A > B:
    print(ans[i].replace('
  else:
    print(ans[i])

Solution (Python):

def solve():
    a, b = map(int, input().split())
    import numpy as np

    unit22 = np.array([[1,1,1,1,1,1],
                       [1,1,0,0,0,1],
                       [1,0,1,0,0,1],
                       [1,0,0,1,0,1],
                       [1,0,0,0,1,1],
                       [1,1,1,1,1,1]])

    unit21 = np.array([[1,1,1,1,1,1],
                       [1,0,0,0,0,1],
                       [1,1,0,0,0,1],
                       [1,0,1,0,1,1],
                       [1,0,0,1,1,1],
                       [1,1,1,1,1,1]])

    unit20 = np.array([[1,1,1,1,1,1],
                       [1,0,1,0,0,1],
                       [1,0,1,0,0,1],
                       [1,0,1,0,0,1],
                       [1,0,1,0,0,1],
                       [1,1,1,1,1,1]])

    unit11 = np.array([[1,1,1,1,1,1],
                       [1,0,0,0,0,1],
                       [1,0,1,1,0,1],
                       [1,0,1,1,0,1],
                       [1,0,0,0,0,1],
                       [1,1,1,1,1,1]])

    unit10 = np.array([[1,1,1,1,1,1],
                       [1,0,0,0,0,1],
                       [1,0,0,0,0,1],
                       [1,0,0,0,0,1],
                       [1,0,0,0,0,1],
                       [1,1,1,1,1,1]])

    unit00 = np.array([[1,1,1,1,1,1],
                       [1,1,1,1,1,1],
                       [1,1,1,1,1,1],
                       [1,1,1,1,1,1],
                       [1,1,1,1,1,1],
                       [1,1,1,1,1,1]])

    str_a = '.'
    str_b = '

    if a > b:
        int_a = 0
        int_b = 1
        sup = a
        inf = b - 1
    else:
        int_a = 1
        int_b = 0
        sup = b
        inf = a - 1

    n = 16*16
    n22=0
    n21=0
    n20=0
    n10=0
    n11=0
    n00=0

    if sup % 2 == 0:
        n22 = inf//2
        n21 = inf%2
        n20 = sup//2 - n22 - n21
        n00 = n - n22 - n21 - n20
    else:
        if inf % 2 == 0:
            n22 = inf//2
            n20 = sup//2 - n22
            n10 = 1
            n00 = n - n22 - n20 - n10
        else:
            n22 = inf//2
            n20 = sup//2 - n22
            n11 = 1
            n00 = n - n22 - n20 - n11

    


    unit_array = []
    for i in range(n22):
        unit_array.append(unit22)
    for i in range(n21):
        unit_array.append(unit21)
    for i in range(n20):
        unit_array.append(unit20)
    for i in range(n11):
        unit_array.append(unit11)
    for i in range(n10):
        unit_array.append(unit10)
    for i in range(n00):
        unit_array.append(unit00)

    res = np.zeros(shape=(96, 96), dtype=object)
    for i in range(16):
        for j in range(16):
            unit = unit_array[i*16+j]
            x = 6*j
            y = 6*i
            res[x:x+6,y:y+6] = unit

    res[res==int_a] = str_a
    res[res==int_b] = str_b

    print('96 96')
    for row in res:
        for col in row:
            print(col, end='')
        print("\n")

solve()

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

    print(100, 100)

    rem = B - 1
    for i in range(50):  
        if i%2 == 1: 
            line = "." * 100
            print(line)
            continue
        line = ""
        for j in range(50):  
            if rem > 0:
                line += "
                rem -= 1
            else:
                line += ".."
        print(line)

    rem = A - 1
    for i in range(50):  
        if i%2 == 0: 
            line = "
            print(line)
            continue
        line = ""
        for j in range(50):  
            if rem > 0:
                line += ".
                rem -= 1
            else:
                line += "
        print(line)


if __name__ == "__main__":
    solve()

Solution (Python):


a, b = map(int, input().split())
h, w = 99, 99
g = [["." for _ in range(w)] for _ in range(h)]
white = 1
black = 0

for i in range(0, h, 3):
    for j in range(0, w, 3):
        if black < b:
            g[i+1][j+1] = "
            black += 1

if a > 1:
    g[1][1] = "."

for i in reversed(range(0, h, 3)):
    for j in reversed(range(0, w, 3)):
        if white < a:
            for k in range(3):
                for l in range(3):
                    g[i+k][j+l] = "
            g[i+1][j+1] = "."
            white += 1

print(h, w)
for i in range(h):
    print("".join(g[i]))

Solution (Python):
line = input().split(" ")
a = max(int(line[0])-1,0)
b = max(int(line[1])-1,0)

h = 100
w = 100
m = []

for hi in range(h):
    if hi<50:
        m.append(["
    else:
        m.append(["." for _ in range(w)])

for ai in range(a//50):
    for i in range(50):
        m[2*ai][2*i] = "."
for ai in range(a%50):
    m[2*(a//50)][2*ai] = "."

for bi in range(b//50):
    for i in range(50):
        m[50+2*bi+1][2*i] = "
for bi in range(b%50):
    m[50+2*(b//50)+1][2*bi] = "

print(str(h)+" "+str(w))
for hi in range(h):
    print("".join(m[hi]))

Solution (Python):

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

QA=(A-1)//50
QB=(B-1)//50
RA=(A-1)%50
RB=(B-1)%50

def PRINTw(x): 
    for j in range(x):
        print(".
    for j in range(50-x):
        print("
    print()
    for j in range(100):
        print("
    print()
def PRINTb(x): 
    for j in range(100):
        print(".",end="")
    print()
    for j in range(x):
        print(".
    for j in range(50-x):
        print("..",end="")
    print()

print("40 100")

for i in range(QA):
    PRINTw(50)
PRINTw(RA)
for i in range(10-(QA+1)):
    PRINTw(0)

for i in range(QB):
    PRINTb(50)
PRINTb(RB)
for i in range(10-(QB+1)):
    PRINTb(0)

Solution (Python):


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

print 100,100

for i in range(100):
    line = ""
    if i < 50:
        if i%2==0:
            for j in range(100):
                if j%2==0:
                    if a > 1:
                        line+="."
                        a -= 1
                    else:
                        line+="
                else:
                    line+="
        else:
            for j in range(100):
                line+="
    else:
        if not i%2==0:
            for j in range(100):
                if j%2==0:
                    if b > 1250:
                        line+="
                    else:
                        line+="."
                        b += 1
                else:
                    line+="."
        else:
            for j in range(100):
                line+="."
    print line

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

print('100 100')

ans = [['
for i in range(1, 99):
    for j in range(50, 99):
        ans[i][j] = '.'

i = 3
j = 3
while A > 0:
    ans[i][j] = '.'
    A -= 1
    i += 2
    if i > 93:
        i = 3
        j += 2

i = 3
j = 53
while B > 0:
    ans[i][j] = '
    B -= 1
    i += 2
    if i > 93:
        i = 3
        j += 2

for s in ans:
    print(''.join(s))

Solution (Python):
def prity(mat, line):
    print(line, 100)
    for i in range(line):
        for j in range(100):
            print(mat[i][j], end='')
        print()

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

if A*B == 1:
    print(1, 2)
    print(".
else:

    mat = [['' for i in range(100)] for j in range(100)]

    
    line=0
    if A > 1: 
        B -= 1
        while A > 1:
            for j in range(50):
                if A > 1:
                    mat[line][2*j] = "."
                    A -= 1
                else:
                    mat[line][2*j] = "
                mat[line][2*j+1] = "
            for j in range(100):
                mat[line+1][j] = "
            line += 2

    
    for j in range(100):
        mat[line][j] = "."
    A -= 1
    line += 1
    assert A == 0
    
    
    if B > 0:
        while B > 0:
            for j in range(50):
                if B > 0:
                    mat[line][2*j] = "
                    B -= 1
                else:
                    mat[line][2*j] = "."
                mat[line][2*j+1] = "."
            for j in range(100):
                mat[line+1][j] = "."
            line += 2

    prity(mat, line)

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

width, height = 100, 100

ans = [['
for _ in range(height//2):
    ans.append(['.'] * width)

for i in range(height // 2 // 2):
    if a == 1:
        break
    for j in range(width // 2):
        if a == 1:
            break
        ans[i*2][j*2] = '.'
        a -= 1

for i in range(height // 2 // 2):
    if b == 1:
        break
    for j in range(width // 2):
        if b == 1:
            break
        ans[-i*2-1][-j*2-1] = '
        b -= 1

print(height, width)
print('\n'.join(map(lambda x: ''.join(x), ans)))

Solution (Python):
a,b=map(int,input().split())
ret=[]
for i in range(50):
    ret.append(list("
for i in range(50):
    ret.append(list("."*100))
a-=1
b-=1
i=0
j=0
while a>0:
    ret[i][j]="."
    j+=2
    a-=1
    if j>=99:
        j=0
        i+=2
i=99
j=0
while b>0:
    ret[i][j]="
    j+=2
    b-=1
    if j>=99:
        j=0
        i-=2
print(100,100)
for i in range(100):
    print("".join(ret[i]))

Solution (Python):

def inpl(): return list(map(int, input().split()))

A, B = inpl()

L = [["."]*50 for i in range(100)]
R = [["

def plot(R):
    print("\n".join(["".join(r) for r in R]))

count = 0
for i in range(11):
    for j in range(48):
        if count == B-1:
            break
        L[j+3*i+1][j+1] = "
        count += 1

count = 0
for i in range(11):
    for j in range(48):
        if count == A-1:
            break
        R[j+3*i+1][j+1] = "."
        count += 1
        
ANS = [l+r for l, r in zip(L, R)]

print(100, 100)
plot(ANS)

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

h,w = (100, 100)
print(h, w)

G = [[ '
A -= 1
B -= 1
for i in range(A // 50):
    for j in range(50):
        G[2*i][j*2] = '.'
for j in range(A % 50):
    G[2*(A // 50)][2*j] = '.'

for i in range(B // 50):
    for j in range(50):
        G[2*i + 40][j*2] = '
for j in range(B % 50):
    G[40 + 2*(B // 50)][2*j] = '

for line in G:
    print("".join(line))

Solution (Python):
def main():
    white, black = [int(e) for e in input().split()]

    w = 100
    h = 50

    line = [0] * w
    field = [list(line) for _ in range(h)]

    white -= 1

    if white > 0:
        black -= 1

        for y in range(0, h, 2):
            for x in range(0, w, 2):
                field[y][x + 1] = field[y + 1][x] = field[y + 1][x + 1] = 1
                white -= 1
                if white == 0:
                    break
            if white == 0:
                break

    if black > 0:
        for y in range(24, h, 2):
            for x in range(0, w, 2):
                field[y][x] = 1
                black -= 1
                if black == 0:
                    break
            if black == 0:
                break

    print('{} {}'.format(h, w))
    for line in field:
        print(''.join(['


if __name__ == '__main__':
    main()

Solution (Python):

A, B = map(int, input().split())
res_list = [["."]*100 for _ in range(20)] + [["
A -= 1
B -= 1
for i in range(0, 20, 2):
    for j in range(0, 100, 2):
        if B > 0:
            res_list[i][j] = "
            B -= 1
for i in range(21, 40, 2):
    for j in range(0, 100, 2):
        if A > 0:
            res_list[i][j] = "."
            A -= 1
print("40 100")
for res in res_list:
    print("".join(res))

Solution (Python):
x, y = map(int, input().split())
r, s = 100, 100
a = [['.' for j in range(s)] for i in range(r)]
for i in range(1, r, 2):
    a[i] = ['.'] + ['
for i in range(r):
    a[i][s - 1] = '

ca, cb = 1, 1
l, d = 2, s - 3
while ca < x:
    for i in range(0, r, 2):
        a[i][d] = '
        ca += 1
        if ca == x:
            break
    d -= 2
while cb < y:
    for i in range(1, r, 2):
        a[i][l] = '.'
        cb += 1
        if cb == y:
            break
    l += 2

print(r, s)
for i in range(r):
    print(''.join(a[i]))

Solution (Python):
A, B = map(int, input().split())
res = []
def make(t, cnt):
    res = []
    for i in range(25):
        res.append([t]*100)
        tmp = [t]*100
        for j in range(50):
            if cnt == 0:
                break
            tmp[2*j] = t^1
            cnt -= 1
        res.append(tmp)
    return res
mp = ".
ans = make(0, B-1) + make(1, A-1)
print(100, 100)
for l in ans:
    print(*map(mp, l), sep='')

Solution (Python):
a, b = map(int, raw_input().split())
print 100, 100
a -= 1
b -= 1
d = [list('
for i in xrange(a):
    x, y = divmod(i, 49)
    d[x*2+1][y*2+1] = '.'
for i in xrange(b):
    x, y = divmod(i, 49)
    d[x*2+51][y*2+1] = '
for r in d:
    print ''.join(r)

Solution (Python):
A,B = map(int, raw_input().split())
G = [['
A -= 1
B -= 1
for y in range(0,50,2):
  for x in range(0,100,2):
    if A>0:
      G[y][x] = '.'
      A -= 1
    if B>0:
      G[99-y][x] = '
      B -= 1
print 100,100
for g in G:
  print "".join(g)