Python 3.11.5 (tags/v3.11.5:cce6ba9, Aug 24 2023, 14:38:34) [MSC v.1936 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> def check_validity(field):
...     ships = {'#': 0, '4': 0, '3': 0, '2': 0, '1': 0}
...     for row in field:
...         for i in range(10):
...             if row[i] == '#':
...                 ships['#'] += 1
... 
...     for i in range(10):
...         for j in range(10):
...             if field[i][j] == '#':
...                 count = 1
...                 if j + 1 < 10 and field[i][j + 1] == '#':
...                     while j + 1 < 10 and field[i][j + 1] == '#':
...                         count += 1
...                         j += 1
...                 if count > 4 or count < 1:
...                     return 'NO'
...                 ships[str(count)] += 1
...                 j -= count - 1
...                 count = 1
...                 if i + 1 < 10 and field[i + 1][j] == '#':
...                     while i + 1 < 10 and field[i + 1][j] == '#':
...                         count += 1
...                         i += 1
...                 if count > 4 or count < 1:
...                     return 'NO'
...                 ships[str(count)] += 1
... 
...     if ships['#'] != 20 or ships['4'] != 1 or ships['3'] != 2 or ships['2'] != 3 or ships['1'] != 4:
...         return 'NO'
... 
...     for i in range(10):
...         for j in range(10):
...             if field[i][j] == '#':
...                 for x in range(max(0, i - 1), min(10, i + 2)):
...                     for y in range(max(0, j - 1), min(10, j + 2)):
                        if field[x][y] == '#' and (x, y) != (i, j):
                            return 'NO'

    return 'YES'



field = []
for _ in range(10):
    row = input()
    field.append(row)

