n=gets.to_i @g=Hash.new{|h, k| h[k]={}} n.times do x, y, _x, _y=gets.split.map(&:to_i) @g[[x, y]][[_x, _y]]=1 @g[[_x, _y]][[x, y]]=1 end @used={} def rec(i, g) @used[i]=1 g<< i @g[i].each_key do |j| unless @used.key?(j) rec(j, g) end end end ok=true @g.each_key do |i| unless @used.key?(i) g=[] rec(i, g) e=g.inject(0){|s, v| s+@g[v].size()} ok&=(g.size+1>e/2) end end puts ok ? "YES": "NO"