Problem:
There is a square-shaped grid with N vertical rows and N horizontal columns. We will denote the square at the i-th row from the top and the j-th column from the left as (i,\ j).  Initially, each square is either white or black. The initial color of the grid is given to you as characters a_{ij}, arranged in a square shape. If the square (i,\ j) is white, a_{ij} is `.`. If it is black, a_{ij} is `#`.  You are developing a robot that repaints the grid. It can repeatedly perform the following operation:    * Select two integers i, j (1 ≤ i,\ j ≤ N). Memorize the colors of the squares (i,\ 1), (i,\ 2), ..., (i,\ N) as c_1, c_2, ..., c_N, respectively. Then, repaint the squares (1,\ j), (2,\ j), ..., (N,\ j) with the colors c_1, c_2, ..., c_N, respectively.  Your objective is to turn all the squares black. Determine whether it is possible, and find the minimum necessary number of operations to achieve it if the answer is positive.

Incorrect submission (verdict: Wrong Answer):
def paint(row,col):
  #print("--> paint:",row, col)
  
  temp = list(ar[row])
  for i in range(N):
    ar[i][col] = temp[i]

def paintsCompletely(row,col):
  
  for i in range(N):
    if ar[i][col] == '.' and ar[row][i] == '.':
      return False
  return True

N = int(input().strip())
ar = [N*[] for _ in range(N)]
for row in range(N):
  ar[row] = list(input().strip())
#print(ar)

count = N*[0]
missing = [N*[] for _ in range(N)]
fullestRow = -1
maxCount = 0
for row in range(N):
  for col in range(N):
    if ar[row][col] == '#':
      count[row] += 1
    else:
      missing[row].append(col)
  if count[row] > maxCount:
    maxCount = count[row]
    fullestRow = row
#print(fullestRow)

if maxCount == 0:
  print(-1)
else:
  req = 0
  for emptyCol in missing[fullestRow]:
    #print(ar)
    #print("empty:",emptyCol)
    req += 1
    found = False
    oneRow = -1
    for row in range(N):
      if ar[row][fullestRow] == '#':
        found = True
        oneRow = row
        #ar[fullestRow][emptyCol] = '#'
        if paintsCompletely(row,emptyCol):
          #print("completely?")
          paint(row,emptyCol)
          break
    if not found:
      #print("Not found")
      paint(fullestRow,emptyCol)
      req += 1
      #ar[fullestRow][emptyCol] = '#'
      for row in range(N):
        if ar[row][fullestRow] == '#':
          oneRow = row
          #ar[fullestRow][emptyCol] = '#'
          if paintsCompletely(row,emptyCol):
            paint(row,emptyCol)
            break
    paint(oneRow, emptyCol)
  #print(ar)
  for col in range(N):
    for row in range(N):
      if ar[row][col] == '.':
        req+=1
        break
  print(req)

Fixed, accepted submission:
N = int(input().strip())
ar = [N*[] for _ in range(N)]
for row in range(N):
  ar[row] = input().strip()

fullestRows = []
maxCount = 0
for row in range(N):
  count = 0
  for col in range(N):
    if ar[row][col] == '#':
      count += 1
  if count > maxCount:
    maxCount = count
    fullestRows = [row]
  elif count == maxCount:
    fullestRows.append(row)

if maxCount == 0:
  print(-1)
else:
  found = False
  req = 0
  for fr in fullestRows:
    for row in range(N):
      if ar[row][fr] == '#':
        found = True
        break
    if found:
      break
  if not found:
    req += 1
  req += N - maxCount
  
  for col in range(N):
    for row in range(N):
      if ar[row][col] == '.':
        req+=1
        break
  print(req)