def d(a,b); (a[0] - b[0]).abs + (a[1] - b[1]).abs; end def num(z); (z[0] * 4 + z[1] + 1) % 16; end S = Array.new(16) 4.times do |y| gets.split.map(&:to_i).each_with_index do |n,x| S[n] = [y,x] end end loop do z = S[0] n = num(z) break if d(S[n], S[0]) != 1 S[0] = S[n] S[n] = z end puts 16.times.all?{|n| num(S[n]) == n } ? "Yes" : "No"