def sol n,d,w,c if c == 0 return w.uniq.sort.reverse.index(w[0]) + 1 end ans = n n.times{|i| (i + 1).upto(n - 1){|j| if d[i][j] == '-' d[i][j] = 'o' d[j][i] = 'x' w[i] += 1 ans = [ans, sol(n,d,w,c - 2)].min d[i][j] = 'x' d[j][i] = 'o' w[i] -= 1 w[j] += 1 ans = [ans, sol(n,d,w,c - 2)].min d[i][j] = '-' d[j][i] = '-' w[j] -= 1 end } } return ans end n = gets.to_i d = Array.new(n) w = Array.new(n,0) c = 0 n.times{|i| d[i] = gets.chomp.split('') n.times{|j| if d[i][j] == 'o' w[i] += 1 elsif d[i][j] == '-' c += 1 end } } 1.upto(n - 1){|i| if d[0][i] == '-' d[0][i] = 'o' d[i][0] = 'x' w[0] += 1 c -= 2 end } p sol(n,d,w,c)