Problem:


正方形探索

縦に n 行、横に n 列並べられた、合計  n &times; n のマス目があります。いくつかのマス目には印がついています。各マス目の印の状態を読み込み、印のついていないマス目だけからなる最大の正方形の辺の長さを出力として表示するプログラムを作成してください。

たとえば各データセットで以下のようなデータが与えられます。

10
...*....**
..........
**....**..
........*.
..*.......
..........
.*........
..........
....*..***
.*....*...

入力データの一行が、一行のマス目を表現します。入力データの文字列のうち、.（ピリオド）は印のついていないマス目、*（アスタリスク）は印のついているマス目を示しています。

上記の例では、下図の 0 で示される正方形が最大となります。

...*....**
..........
**....**..
...00000*.
..*00000..
...00000..
.*.00000..
...00000..
....*..***
.*....*...

よって、5 と出力すれば正解になります。

なお、すべてのマス目に印がついている場合には、0 を出力してください。

Input

上記形式で複数のデータセットが与えられます。
n が 0 のとき入力の最後とします。n は 1000 以下とします。入力データの文字列には、ピリオド、アスタリスク、改行以外の文字は含まれません。データセットの数は 50 を超えません。

Output

各データセットに対し、最大の正方形の辺の長さ（整数）を１行に出力して下さい。

Sample Input

10
...*....**
..........
**....**..
........*.
..*.......
..........
.*........
..........
....*..***
.*....*...
10
****.*****
*..*.*....
****.*....
*....*....
*....*****
..........
****.*****
*..*...*..
****...*..
*..*...*..
0

Output for the Sample Input

5
3



Sample input:
10
...*....**
..........
**....**..
........*.
..*.......
..........
.*........
..........
....*..***
.*....*...
10
****.*****
*..*.*....
****.*....
*....*....
*....*****
..........
****.*****
*..*...*..
****...*..
*..*...*..
0


Sample output:
5
3

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0092
"""
import sys


def find_square0(data):
    max_size = 0
    dp = [] # dp??¨???2?¬??????????
    # '.'????????????1??????'*'????????????0????????????
    for row in data:
        temp = []
        for c in row:
            if c == '.':
                temp.append(1)
            else:
                temp.append(0)
        dp.append(temp)

    # ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????
    for y in range(1, len(dp)):
        for x in range(1, len(dp[0])):
            if dp[y][x] == 1:
                dp[y][x] = min(dp[y-1][x-1], dp[y-1][x], dp[y][x-1]) + 1
                if dp[y][x] > max_size:
                    max_size = dp[y][x]
    return max_size


def find_square2(data):
    max_size = 0
    dp = [[0]*len(data[0]) for _ in range(len(data))] # dp??¨???2?¬???????????????¨??????0??§?????????
    # '.'????????????1???
    for y, row in enumerate(data):
        for x, c in enumerate(row):
            if c == '.':
                dp[y][x] = 1

    # (?????¨???(curr_row)??¨???????????????(prev_row)????????¢????????????????????§?????????????????????)
    prev_row = dp[0]
    for curr_row in dp[1:]:
        for x, t in enumerate(curr_row[1:], start=1):
            if t == 1:
                curr_row[x] = min(prev_row[x-1], prev_row[x], curr_row[x-1]) + 1
                if curr_row[x] > max_size:
                    max_size = curr_row[x]
        prev_row = curr_row
    return max_size


def find_square3(data):
    from array import array
    max_size = 0
    dp = [array('I', [0]*len(data[0])) for _ in range(len(data))]  # ????¬?????????????array??????????????§?¢????
    # '.'????????????1???
    for y, row in enumerate(data):
        for x, c in enumerate(row):
            if c == '.':
                dp[y][x] = 1

    prev_row = dp[0]
    for curr_row in dp[1:]:
        for x, t in enumerate(curr_row[1:], start=1):
            if t == 1:
                curr_row[x] = min(prev_row[x-1], prev_row[x], curr_row[x-1]) + 1
                if curr_row[x] > max_size:
                    max_size = curr_row[x]
        prev_row = curr_row
    return max_size


def find_square4(data):
    # 4.91[s]
    max_size = 0
    dp = [0 for _ in range(1024*1024)]
    # '.'????????????1???
    for y, row in enumerate(data):
        for x, c in enumerate(row):
            if c == '.':
                dp[y*1024+x] = 1

    # ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????
    for y in range(1, len(data)):
        for x in range(1, len(data)):
            if dp[y*1024+x] == 1:
                dp[y*1024+x] = min(dp[(y-1)*1024+x-1], dp[(y-1)*1024+x], dp[y*1024+x-1]) + 1
                if dp[y*1024+x] > max_size:
                    max_size = dp[y*1024+x]
    return max_size



def main(args):
    while True:
        n = int(input())
        if n == 0:
            break
        data = [input() for _ in range(n)]
        result = find_square2(data)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    inp = []
    for i in range(n):
        inp.append(list(input()))
    
    sq_max = [[0 for i in range(n + 1)] for j in range(n + 1)]
    
    for y in range(n):
        for x in range(n):
            if inp[y][x] == ".":
                sq_max[y + 1][x + 1] = min(sq_max[y][x + 1], sq_max[y + 1][x], sq_max[y][x]) + 1
            else:
                sq_max[y + 1][x + 1] = 0
    ans = max(map(max, sq_max))
    print(ans)

Submission status: Accepted

Solution code:
while True:
  n = int(input())
  if not n:
    break
  mp = []
  for _ in range(n):
    lst = list(input())
    cum = []
    acc = 0
    for i in lst:
      if i == ".":
        acc += 1
      else:
        acc = 0
      cum.append(acc)
    mp.append(cum)
  mp.append([-1] * n)
  ans = 0
  
  for i in range(n):
    stack = []
    for j in range(n + 1):
      score = mp[j][i]
      if not stack:
        stack.append((score, j))
      else:
        last_score, last_ind = stack[-1][0], stack[-1][1]
        if score > last_score:
          stack.append((score, j))
        
        elif score == last_score:
          continue
        
        else:
          while stack != [] and stack[-1][0] >= score:
            last_score, last_ind = stack.pop()
            ans = max(ans, min(last_score, j - last_ind))
          stack.append((score, last_ind))
  
  print(ans)

Submission status: Accepted

Solution code:
# AOJ 0092 Square Searching
# Python3 2018.6.21 bal4u

cin = [['' for c in range(1002)] for r in range(1002)]
dp =  [[0 for c in range(1002)] for r in range(1002)]
while 1:
	n = int(input())
	if n == 0: break
	for r in range(n):
		cin[r] = list(input())
	ans = 0
	for r in range(n):
		for c in range(n):
			if cin[r][c] == '*': dp[r][c] = 0
			else :
				t = dp[r-1][c-1]
				if t > 0 and dp[r  ][c-1] < t: t = dp[r  ][c-1];
				if t > 0 and dp[r-1][c  ] < t: t = dp[r-1][c  ];
				t += 1
				dp[r][c] = t
				if t > ans: ans = t
	print(ans)

Submission status: Accepted

Solution code:
# AOJ 0092 Square Searching
# Python3 2018.6.21 bal4u

cin = [[''] for r in range(1002)]
dp =  [[0 for c in range(1002)] for r in range(1002)]
while 1:
	n = int(input())
	if n == 0: break
	for r in range(n):
		cin[r] = input()
	ans = 0
	for r in range(n):
		for c in range(n):
			if cin[r][c] == '*': dp[r][c] = 0
			else :
				t = dp[r-1][c-1]
				if t > 0 and dp[r  ][c-1] < t: t = dp[r  ][c-1];
				if t > 0 and dp[r-1][c  ] < t: t = dp[r-1][c  ];
				t += 1
				dp[r][c] = t
				if t > ans: ans = t
	print(ans)

Submission status: Accepted

Solution code:
# AOJ 0092 Square Searching
# Python3 2018.6.21 bal4u

cin = [[''] for r in range(1002)]
dp =  [[0 for c in range(1002)] for r in range(1002)]
while 1:
	n = int(input())
	if n == 0: break
	for r in range(n): cin[r] = input()
	ans = 0
	for r in range(n):
		for c in range(n):
			if cin[r][c] == '*': dp[r][c] = 0
			else :
				t = dp[r-1][c-1]
				if dp[r  ][c-1] < t: t = dp[r  ][c-1];
				if dp[r-1][c  ] < t: t = dp[r-1][c  ];
				t += 1
				dp[r][c] = t
				if t > ans: ans = t
	print(ans)

Submission status: Accepted

Solution code:
# AOJ 0092 Square Searching
# Python3 2018.6.21 bal4u

cin = [[''] for r in range(1002)]
dp =  [[0 for c in range(1002)] for r in range(1002)]
while 1:
	n = int(input())
	if n == 0: break
	for r in range(n): cin[r] = input()
	ans = 0
	for r in range(n):
		for c in range(n):
			if cin[r][c] == '*': dp[r][c] = 0
			else :
				t = 1+min(dp[r-1][c-1], dp[r][c-1], dp[r-1][c])
				dp[r][c] = t
				if t > ans: ans = t
	print(ans)

Submission status: Accepted

Solution code:
while True:
    n=input()
    if n==0:
        break
    board=[""]*n
    for i in xrange(n):
        board[i]=raw_input()
    dp=[[0]*(n+1) for unused in xrange(n+1)]
    for y in xrange(n):
        for x in xrange(n):
            if board[y][x]==".":
                dp[y][x]=min(dp[y][x-1],dp[y-1][x],dp[y-1][x-1])+1
    print max(map(max,dp))

Submission status: Accepted

Solution code:
while 1:
    n = int(raw_input())
    if n == 0:
        break
    dp = [[0] * n for i in range(n)]
    r = 0
    for i in range(n):
        for j, ch in enumerate(raw_input()):
            if ch == '*':
                continue
            dp[i][j] = 1
            if i >= 1 or j >= 1:
                dp[i][j] += min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1])
            r = max(r, dp[i][j])
    print r

Submission status: Accepted

Solution code:
while True:
    n=input()
    if n==0:break
    L=[list(raw_input()) for i in range(n)]
    dp=[[0]*n for i in range(n)]
    maxInt=0
    for i in range(n):
        for j in range(n):
            if i==0 and L[i][j]==".":
                dp[i][j]=1
            if j==0 and L[i][j]==".":
                dp[i][j]=1
            if L[i][j]==".":
                dp[i][j]=1+min(dp[i-1][j],dp[i][j-1],dp[i-1][j-1])
            maxInt=max(maxInt,dp[i][j])
    print maxInt

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def main(readline=stdin.readline):
    while 1:
        n = int(readline())
        if not n:
            exit()

        pre = [0] * (n+1)
        now = [0] * (n+1)
        maximum = 0

        for _ in range(n):
            for x, c in enumerate(readline().rstrip(), 1):
                if c == '.':
                    now[x] = min(pre[x-1], pre[x], now[x-1]) + 1
                    if maximum < now[x]:
                        maximum = now[x]
            pre = now
            now = [0] * (n+1)

        print(maximum)


main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def main(readline=stdin.readline):
    while 1:
        n = int(readline())
        if not n:
            exit()

        pre = [0] * (n+1)
        now = [0] * (n+1)
        maximum = 0

        for _ in range(n):
            for x, c in enumerate(readline().rstrip(), 1):
                if c == '.':
                    now[x] = min(pre[x-1], pre[x], now[x-1]) + 1
                    if maximum < now[x]:
                        maximum = now[x]

            for x in range(1, n+1):
                pre[x] = now[x]
                now[x] = 0

        print(maximum)


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
    n = int(raw_input())
    if n == 0: break
    field = [raw_input() for i in range(n)]
    large = [[0] * (n + 1) for i in range(n + 1)]
    mx = 0
    for i in range(n):
        for j in range(n):
            if field[i][j] == '.':
                large[i][j] = min(large[i][j - 1], large[i - 1][j], large[i - 1][j - 1]) + 1
                if large[i][j] > mx:
                	mx = large[i][j]
    print mx

Submission status: Accepted

Solution code:
while True:
    n = int(raw_input())
    if n == 0: break
    field = [raw_input() for i in range(n)]
    large = [[0]*(n + 1) for i in range(n + 1)]
    mx = 0
    for i in range(n):
        for j in range(n):
            if field[i][j] == '.':
                large[i][j] = min(large[i][j - 1], large[i - 1][j], large[i - 1][j - 1]) + 1
    print max(map(max, large))

Submission status: Accepted

Solution code:
while True:
    n = int(raw_input())
    if n == 0: break
    field = [raw_input() for i in range(n)]
    large = [[0]*(n + 1) for i in range(n + 1)]
    for i in range(n):
        for j in range(n):
            if field[i][j] == '.':
                large[i][j] = min(large[i][j - 1], large[i - 1][j], large[i - 1][j - 1]) + 1
    print max(map(max, large))

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    N = int(readline())
    if N == 0:
        return False
    f = ".*".index
    MP = [list(map(f, readline().strip())) for i in range(N)]
    D = [[0]*N for i in range(N)]
    ds = [0]*N
    for i in range(N):
        MPi = MP[i]
        Di = D[i]
        for j in range(N):
            if MPi[j]:
                ds[j] = 0
            else:
                ds[j] += 1
                Di[j] = ds[j]
    ans = 0
    def gen():
        for i in range(N):
            st = []
            Di = D[i]
            for j in range(N):
                c = Di[j]
                last = j
                while st and st[-1][1] >= c:
                    k, d = st.pop()
                    yield min(d, j-k)
                    last = k
                st.append((last, c))
            while st:
                k, d = st.pop()
                yield min(d, N-k)
    write("%d\n" % max(gen()))
    return True
while solve():
    ...

Submission status: Accepted

Solution code:
# don't know good 参考:http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2954794#1

table = [''] * 1002
dp = [[0] * 1002 for i in range(1002)]

while 1:
	n = int(input())
	if n == 0: break
	for r in range(n): table[r] = input()
	ans = 0
	
	for r in range(n):
		for c in range(n):
			if table[r][c] == '*': dp[r][c] = 0
			else :
				t = dp[r-1][c-1]
				if dp[r  ][c-1] < t: t = dp[r  ][c-1];
				if dp[r-1][c  ] < t: t = dp[r-1][c  ];
				t += 1
				dp[r][c] = t
				if t > ans: ans = t
	print(ans)

Submission status: Accepted

Solution code:
from itertools import chain

while True:
    n = int(input())
    if not n:
        break
    dp = [[0]*(n+1) for _ in [0]*(n+1)]
    for y, (l_u, l_c) in enumerate(zip(dp, dp[1:]), start=1):
        for x, (c, ul, u, left) in enumerate(zip(input(), l_u, l_u[1:], l_c), start=1):
            dp[y][x] = min(ul, u, left)+1 if c == "." else 0

    print(max(chain.from_iterable(dp)))

Submission status: Runtime Error

Solution code:
import sys

while 1:
  n=input()+1
  if n==1:break
  A=[''*n]+[' '+raw_input() for i in range(1,n)]
  M=[[0]*n for i in range(n)]
  for i in range(1,n):
    for j in range(1,n):
      if A[i][j]=='.':
        M[i][j]=min(M[i-1][j-1],M[i-1][j],M[i][j-1])+1
  print max(map(max,M))
        a=min(M[i-1][j-1],M[i-1][j],a)+1
        M[i][j]=a
  print max(map(max,M))

Submission status: Runtime Error

Solution code:
import sys
while 1:
  n = input() + 1
  if n==1: break
  N = range(n)
  M = [[0] * n for i in N]
  y = M[0]
  for i in N[1:]:
    x = [0] * n
    A = ' ' + raw_input()
    for j in N[1:]:
      if A[j] == '.': x[j] = min(y[j-1],　y[j],　x[j-1]) + 1
    M[i] = x
    y = x
  print max(map(max,　M))

Submission status: Runtime Error

Solution code:
while True:
    n = input()
    if n==0:
        break
    data=[]
    for i in range(n):
        data.append(raw_input())
    solve=0
    for i in range(n):
        if i+solve<n:
            for j in range(n):
                if j+solve<n:
                    while True:
                        flag=0
                        for a in range(solve+1):
                            for b in range(solve+1):
                                if data[i+a][j+b]=="*":
                                    flag=1
                                    break
                            if flag==1:
                                break
                        if flag==0:
                            solve+=1
                        else:
                            break
                else:
                    break
        else:
            break
    print solve

Submission status: Runtime Error

Solution code:
while True:
    n = input()
    if n==0:
        break
    data=[]
    for i in range(n):
        data.append(raw_input())
    d=[[1 for i in range(n)]for j in range(n)]
    solve=0
    for i in range(n):
        if i+solve<n:
            for j in range(n):
                if j+solve<n:
                    if d[i][j]!=0:
                        while True:
                            flag=0
                            for a in reversed(range(solve+1)):
                                for b in reversed(range(solve+1)):
                                    if data[i+a][j+b]=="*":
                                        for v in range(a+1):
                                            for w in range(b+1):
                                                d[i+v][j+w]=0
                                        flag=1
                                        break
                                if flag==1:
                                    break
                            if flag==0:
                                solve+=1
                                if i+solve>=n or j+solve>=n: 
                                    break
                            else:
                                break
                else:
                    break
        else:
            break
    print solve

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0092
"""
import sys


def find_square0(data):
    max_size = 0
    lmap = [] # dp??¨???2?¬??????????
    # '.'????????????0??????'*'????????????1????????????
    for row in data:
        temp = []
        for c in row:
            if c == '.':
                temp.append(1)
            else:
                temp.append(0)
        lmap.append(temp)

    # ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????
    for y in range(1, len(lmap)):
        for x in range(1, len(lmap[0])):
            if lmap[y][x] == 1:
                lmap[y][x] = min(lmap[y-1][x-1], min(lmap[y-1][x], lmap[y][x-1])) + 1
                if lmap[y][x] > max_size:
                    max_size = lmap[y][x]
    return max_size


def find_square(data):
    max_size = 0
    lmap = []
    for row in data:
        temp = []
        for c in row:
            if c == '.':
                temp.append(1)
            else:
                temp.append(0)
        lmap.append(temp)

    prev_row = lmap[0]
    for curr_row in lmap[1:]:
        for x in range(1, len(lmap[0])):
            if curr_row[x] == 1:
                if prev_row[x-1] != 0 and prev_row[x] != 0 and curr_row[x-1] != 0: #  ???????????¶?????????
                    curr_row[x] = min(prev_row[x-1], min(prev_row[x], curr_row[x-1])) + 1
                    if curr_row[x] > max_size:
                        max_size = curr_row[x]
        prev_row = curr_row
    return max_size


def find_square2(data):
    max_size = 0
    lmap = [] # dp??¨???2?¬??????????
    # '.'????????????0??????'*'????????????1????????????
    for row in data:
        temp = []
        for c in row:
            if c == '.':
                temp.append(1)
            else:
                temp.append(0)
        lmap.append(temp)

    # ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????
    # (?????¨???(curr_row)??¨???????????????(prev_row)????????¢????????????????????§?????????????????????)
    prev_row = lmap[0]
    for curr_row in lmap[1:]:
        for x, t in enumerate(curr_row[1:], start=1):
            if t == 1:
                curr_row[x] = min(prev_row[x-1], min(prev_row[x], curr_row[x-1])) + 1
                if curr_row[x] > max_size:
                    max_size = curr_row[x]
        prev_row = curr_row
    return max_size


def find_square3(data):
    from array import array
    max_size = 0
    lmap = [array('B', [0]*len(data[0])) for _ in range(len(data))]
    # '.'????????????0??????'*'????????????1????????????
    for y, row in enumerate(data):
        for x, c in enumerate(row):
            if c == '.':
                lmap[y][x] = 1

    # ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????
    # (?????¨???(curr_row)??¨???????????????(prev_row)????????¢????????????????????§?????????????????????)
    prev_row = lmap[0]
    for curr_row in lmap[1:]:
        for x, t in enumerate(curr_row[1:], start=1):
            if t == 1:
                curr_row[x] = min(prev_row[x-1], min(prev_row[x], curr_row[x-1])) + 1
                if curr_row[x] > max_size:
                    max_size = curr_row[x]
        prev_row = curr_row
    return max_size


def main(args):
    while True:
        n = int(input())
        if n == 0:
            break
        data = [input() for _ in range(n)]
        result = find_square3(data)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0092
"""
import sys


def find_square0(data):
    max_size = 0
    dp = [] # dp??¨???2?¬??????????
    # '.'????????????1??????'*'????????????0????????????
    for row in data:
        temp = []
        for c in row:
            if c == '.':
                temp.append(1)
            else:
                temp.append(0)
        dp.append(temp)

    # ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????
    for y in range(1, len(dp)):
        for x in range(1, len(dp[0])):
            if dp[y][x] == 1:
                dp[y][x] = min(dp[y-1][x-1], dp[y-1][x], dp[y][x-1]) + 1
                if dp[y][x] > max_size:
                    max_size = dp[y][x]
    return max_size


def find_square2(data):
    max_size = 0
    dp = [[0]*len(data[0]) for _ in range(len(data))] # dp??¨???2?¬???????????????¨??????0??§?????????
    # '.'????????????1???
    for y, row in enumerate(data):
        for x, c in enumerate(row):
            if c == '.':
                dp[y][x] = 1

    # (?????¨???(curr_row)??¨???????????????(prev_row)????????¢????????????????????§?????????????????????)
    prev_row = dp[0]
    for curr_row in dp[1:]:
        for x, t in enumerate(curr_row[1:], start=1):
            if t == 1:
                curr_row[x] = min(prev_row[x-1], prev_row[x], curr_row[x-1]) + 1
                if curr_row[x] > max_size:
                    max_size = curr_row[x]
        prev_row = curr_row
    return max_size


def find_square3(data):
    from array import array
    max_size = 0
    dp = [array('I', [0]*len(data[0])) for _ in range(len(data))]  # ????¬?????????????array??????????????§?¢????
    # '.'????????????1???
    for y, row in enumerate(data):
        for x, c in enumerate(row):
            if c == '.':
                dp[y][x] = 1

    prev_row = dp[0]
    for curr_row in dp[1:]:
        for x, t in enumerate(curr_row[1:], start=1):
            if t == 1:
                curr_row[x] = min(prev_row[x-1], prev_row[x], curr_row[x-1]) + 1
                if curr_row[x] > max_size:
                    max_size = curr_row[x]
        prev_row = curr_row
    return max_size


def find_square4(data):
    max_size = 0
    dp = [[0]*1024*1024]
    # '.'????????????1???
    for y, row in enumerate(data):
        for x, c in enumerate(row):
            if c == '.':
                dp[y*1024+x] = 1

    # ????±?????????????????????????????????£????????????????????£?????¢????¢??????§??????????????§????????????
    for y in range(1, len(dp)):
        for x in range(1, len(dp[0])):
            if dp[y*1024+x] == 1:
                dp[y*1024+x] = min(dp[(y-1)*1024+x-1], dp[(y-1)*1024+x], dp[y*1024+x-1]) + 1
                if dp[y*1024+x] > max_size:
                    max_size = dp[y*1024+x]
    return max_size



def main(args):
    while True:
        n = int(input())
        if n == 0:
            break
        data = [input() for _ in range(n)]
        result = find_square4(data)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Runtime Error

Solution code:
n = int(raw_input())
s = [[] for i in range(n)]
flag = 0
for i in range(n):
    s[i] = raw_input()
for i in range(n,1,-1):
    for j in range(n-i+1):
        for k in range(n-i+1):
            out = ""
            for l in range(i):
                for m in range(i):
                    out += s[j+l][k+m]
            if out = "."*i:
                print i
                flag = 1
            if flag == 1: break
        if flag == 1: break
    if flag == 1: break

Submission status: Runtime Error

Solution code:
while True:
    n = int(raw_input())
    if n == 0:
        break
    s = [[] for i in range(n)]
    flag = 0
    for i in range(n):
        s[i] = raw_input()
        for i in range(n,1,-1):
            for j in range(n-i+1):
                for k in range(n-i+1):
                    out = ""
                    for l in range(i):
                        for m in range(i):
                            out += s[j+l][k+m]
                    if out.count("*") == 0:
                        print i
                        flag = 1
                if flag == 1: break
            if flag == 1: break
        if flag == 1: break
    if flag == 0:
        print 1

Submission status: Runtime Error

Solution code:
while True:
    n = int(raw_input())
    if n == 0:
        break
    s = [[] for i in range(n)]
    for i in range(n):
        s[i] = raw_input()
    for i in range(n,0,-1):
        for j in range(n-i+1):
            for k in range(n-i+1):
                flag = 0
                for l in range(i):
                    for m in range(i):
                        if s[j+l][k+m] = "*":
                            flag = 1
                            break
                if flag == 0:
                    print i
                else:
                    break
            if flag == 1: break
        if flag == 1: break
    if flag == 0:
        print 0

Submission status: Runtime Error

Solution code:
l = {".":1,"*":0}
def x(a):
    m=0
    for c in N:
        p=[0]*n 
        for e in range(c,n):
            for r in N:
                p[r]+=l[a[r][e]]
            m=max(P(p),m)
    return m
def P(a):
    m = 0
    for i in N:
        m+=l[a[i]]
    return m
while True:
    n = input()
    if n == 0: break
    N = range(n)
    print x([map(int, raw_input().split()) for i in N])