Buggy python submission (verdict: Time Limit Exceeded):
while True:
    n = int(raw_input())
    r = 0
    if n == 0:
        break
    s = [map(int, raw_input().replace('.','0').replace('*','1')) for i in range(n)]
    sum = [[0] * (n + 1) for i in range(n + 1)]
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            sum[i][j] += s[i - 1][j - 1]
            sum[i][j] += (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1])
    for size in range(n, 0, -1):
        for i in range(size, n + 1):
            for j in range(size, n + 1):
                s = sum[i][j] - sum[i - size][j] - sum[i][j - size] + sum[i - size][j - size]
                if s == 0:
                    r = max(r, size)
                    break
    print r

Fixed submission:
while True:
    n = int(raw_input())
    if n == 0:
        break
    s = [raw_input() for i in range(n)]
    dp = [[0] * (n + 1) for i in range(n + 1)]
    for i in range(n):
        for j in range(n):
            if s[i][j] == '.':
                dp[i][j] = min(dp[i][j - 1], dp[i - 1][j], dp[i - 1][j - 1]) + 1
    print max(map(max, dp))

Buggy python submission (verdict: Time Limit Exceeded):
def m(sum, n):
    for size in range(n, 0, -1):
        for i in range(size, n + 1):
            for j in range(size, n + 1):
                s = sum[i][j] - sum[i - size][j] - sum[i][j - size] + sum[i - size][j - size]
                if s == 0:
                    return size
    return 0

while True:
    n = int(raw_input())
    if n == 0:
        break
    s = [map(int, raw_input().replace('.','0').replace('*','1')) for i in range(n)]
    sum = [[0] * (n + 1) for i in range(n + 1)]
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            sum[i][j] += s[i - 1][j - 1]
            sum[i][j] += (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1])
    print m(sum, n)

Fixed submission:
while True:
    n = int(raw_input())
    if n == 0:
        break
    s = [raw_input() for i in range(n)]
    dp = [[0] * (n + 1) for i in range(n + 1)]
    for i in range(n):
        for j in range(n):
            if s[i][j] == '.':
                dp[i][j] = min(dp[i][j - 1], dp[i - 1][j], dp[i - 1][j - 1]) + 1
    print max(map(max, dp))

Buggy python submission (verdict: Time Limit Exceeded):
def check(sum, i, j, size):
    s = sum[i][j] - sum[i - size][j] - sum[i][j - size] + sum[i - size][j - size]
    return s == 0

def mm(sum, n, size):
    for i in range(size, n + 1):
            for j in range(size, n + 1):
                if check(sum, i, j, size):
                    return True
    return False

def m(sum, n):
    r = 0
    left, mid, right = 0, 0, n
    while left <= right:
        mid = (left + right) / 2
        if mm(sum, n, mid):
            r = max(r, mid)
            left = mid + 1
        else:
            if left == right:
                break
            right = mid
    return r

while True:
    n = int(raw_input())
    if n == 0:
        break
    s = [map(int, raw_input().replace('.','0').replace('*','1')) for i in range(n)]
    sum = [[0] * (n + 1) for i in range(n + 1)]
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            sum[i][j] += s[i - 1][j - 1]
            sum[i][j] += (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1])
    print m(sum, n)

Fixed submission:
while True:
    n = int(raw_input())
    if n == 0:
        break
    s = [raw_input() for i in range(n)]
    dp = [[0] * (n + 1) for i in range(n + 1)]
    for i in range(n):
        for j in range(n):
            if s[i][j] == '.':
                dp[i][j] = min(dp[i][j - 1], dp[i - 1][j], dp[i - 1][j - 1]) + 1
    print max(map(max, dp))

Buggy python submission (verdict: Time Limit Exceeded):
def check(sum, i, j, size):
    s = sum[i][j] - sum[i - size][j] - sum[i][j - size] + sum[i - size][j - size]
    return s == 0

def mm(sum, n, size):
    for i in xrange(size, n + 1):
            for j in xrange(size, n + 1):
                if check(sum, i, j, size):
                    return True
    return False

def m(sum, n):
    r = 0
    left, mid, right = 0, 0, n
    while left <= right:
        mid = (left + right) / 2
        if mm(sum, n, mid):
            r = max(r, mid)
            left = mid + 1
        else:
            if left == right:
                break
            right = mid
    return r

while True:
    n = int(raw_input())
    if n == 0:
        break
    s = [map(int, raw_input().replace('.','0').replace('*','1')) for i in xrange(n)]
    sum = [[0] * (n + 1) for i in xrange(n + 1)]
    for i in xrange(1, n + 1):
        for j in xrange(1, n + 1):
            sum[i][j] += s[i - 1][j - 1]
            sum[i][j] += (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1])
    print m(sum, n)

Fixed submission:
while True:
    n = int(raw_input())
    if n == 0:
        break
    s = [raw_input() for i in range(n)]
    dp = [[0] * (n + 1) for i in range(n + 1)]
    for i in range(n):
        for j in range(n):
            if s[i][j] == '.':
                dp[i][j] = min(dp[i][j - 1], dp[i - 1][j], dp[i - 1][j - 1]) + 1
    print max(map(max, dp))