def hoge x, a if a[x - 1] == x return true end if x % 4 != 0 && a[x] == x return true end if x % 4 != 1 && a[x - 2] == x return true end if x > 4 && a[x - 5] == x return true end if (x - 1) / 4 != 3 && a[x + 3] == x return true end return false end a = STDIN.map{|s|s.split.map(&:to_i)}.flatten 1.upto(15){|x| if hoge(x, a) next end puts 'No' exit } puts 'Yes'