def is_valid_battlefield(field):
    # Сортируем поле по столбцам и строкам
    field = sorted(field)
    
    # Проверяем, что все клетки поля заполнены символами '#' или '.'.
    if not all(c == '#' or c == '.') for c in field):
        return 'NO'
    
    # Проверяем, что каждая клетка на поле имеет символ '#' или '.'.
    if not all(c == '#' or c == '.') for c in field[::-1]):
        return 'NO'
    
    # Проверяем, что множество клеток, занимаемых каждым кораблем, образует прямоугольник соответствующего размера.
    for i in range(len(field)):
        for j in range(len(field[i]))):
            if field[i][j] != '#':
                continue
            if j > 0 and field[i][j-1] == '#':
                continue
            if j < len(field[i]) - 1 and field[i][j+1] == '#':
                continue
            if i > 0 and field[i-1][j] == '#':
                continue
            if i < len(field) - 1 and field[i+1][j] == '#':
                continue
            if j > 0 and j < len(field[i]) - 1 and field[i][j-1] == '#' and field[i][j+1] == '#':
                continue
            if i > 0 and i < len(field) - 1 and field[i-1][j] == '#' and field[i+1][j] == '#':
                continue
            if j > 0 and j < len(field[i]) - 1 and field[i][j-1] == '#' and field[i][j+1] == '#':
                continue
            if i > 0 and i < len(field) - 1 and field[i-1][j] == '#' and field[i][j+1] == '#':
                continue
            if j > 0 and j < len(field[i]) - 1 and field[i][j-1] == '#' and field[i][j+1] == '#':
                continue
            if i > 0 and i < len(field) - 1 and field[i-1][j] == '#' and field[i][j+1] == '#':
                continue
            if j > 0 and j < len(field[i]) - 1 and field[i][j-1] == '#' and field[i][j+1] == '#':
                continue
            if i > 0 and i < len(field) - 1 and field[i-1][j] == '#' and field[i][j+1] == '#':
                continue
            if j > 0 and j < len(field[i]) - 1 and field[i][j-1] == '#' and field[i][j+1] == '#':
                continue
            if i > 0 and i < len(field) - 1 and field[i-1][j] == '#' and field[i][j+1] == '#':
                continue
            if j > 0 and j < len(field[i]) - 1 and field[i][j-1] == '#' and field[i][j+1] == '#':
                continue
            if i > 0 and i < len(field) - 1 and field[i-1][j] == '#' and field[i][j+1] == '#':
                continue
            if j > 0 and j < len(field[i]) - 1 and field[i][j-1] == '#' and field[i][j+1] == '#':
                continue
            if i > 0 and i < len(field) - 1 and field[i-1][j] == '#' and field[i][j+1] == '#':
                continue
            if j > 0 and j < len(field[i]) - 1 and field[i][j-1] == '#' and field[i][j+1] == '#':
                continue
            if i > 0 and i < len(field)
