N, K = gets.split.map &:to_i L = gets.split.map &:to_i board = $<.map{|s| s.chomp.chars } rows = board.map{|a| (a*"").to_i 2 } cols = board.transpose.map{|a| (a*"").to_i 2 } def count_white(a) a.map{|b| ("%b"%b).count ?0 }.sum end FirstScore = count_white(rows) def calc_score(a) count_white(a) - FirstScore end L.each{|l| n = 1 (l - 1).times{ n = (n << 1) | 1 } start = rand(1..N-l+1) n << (N - start) horizonalp = rand(2) > 0 idx = rand(N) m = 1 << (N - idx - 1) if horizonalp rows[idx] ^= n cols.map!{|a| a ^= m } else cols[idx] ^= n rows.map!{|a| a ^= m } end a = b = c = d = 0 if horizonalp a = c = idx + 1 b = start d = start + l - 1 else b = d = idx + 1 a = start c = start + l - 1 end puts [a, b, c, d] * " " } # p calc_score(rows)