a=gets.to_i.times.map{gets.split.map(&:to_i).sort}.sort{|a,b|b.inject(:*)<=>a.inject(:*)} F=->a,i,l,m{ r=0 (a.size-1).downto(i){|j| v=a[j] if v[0]r end } m[i]=r } p F[a,0,[10**8,10**8,10**8],{}]