n = gets.to_i xyz = (1..n).map { gets.split.map(&:to_i).sort }.sort.reverse dp = [1] * n (1...n).each { |i| dp[i] = ((0...i).select { |j| (0...3).all? { |k| xyz[i][k] < xyz[j][k] } }.map { |i| dp[i] }.max || 0) + 1 } puts dp.max