INIT = -10_000_000
N = gets.to_i
S = gets.split.map(&:to_i)

dp1 = Array.new(N + 1, INIT)
class << dp1
  def chmax(i, v)
    self[i] = v if v > self[i]
  end
end

dp2 = Array.new(N + 1){ Array.new(N + 1, INIT) }
class << dp2
  def chmax(i,j,v)
    self[i][j] = v if v > self[i][j]
  end
end

S[0,2].sort.tap do |a,b|
  dp2.chmax(a,b,0)
  dp1.chmax(a,0)
  dp1.chmax(b,0)
end

q = []
base = 0

(1 .. N - 1).each do |i|
  c,d,e = S[3 * i - 1, 3].sort
  if c == e
    base += 1
    next
  elsif c == d
    if dp1[c] >= 0
      (1 .. N).each do |x|
        if x < c
          q << [x, e, dp2[x][c] + 1] if dp2[x][c] >= 0
        elsif x < e
          q << [x, e, dp2[c][x] + 1] if dp2[c][x] >= 0
        else
          q << [e, x, dp2[c][x] + 1] if dp2[c][x] >= 0
        end
      end
    end
    if dp2[e][e] >= 0
      q << [c,d, dp2[e][e] + 1]
    end
  elsif d == e
    if dp1[e] >= 0
      (1 .. N).each do |x|
        if x < c
          q << [x, c, dp2[x][e] + 1] if dp2[x][e] >= 0
        elsif x < e
          q << [c, x, dp2[x][e] + 1] if dp2[x][e] >= 0
        else
          q << [c, x, dp2[e][x] + 1] if dp2[e][x] >= 0
        end
      end
    end
    if dp2[c][c] >= 0
      q << [d, e, dp2[c][c] + 1]
    end
  else
    q << [ d, e, dp2[c][c] + 1] if dp2[c][c] >= 0
    q << [ c, e, dp2[d][d] + 1] if dp2[d][d] >= 0
    q << [ c, d, dp2[e][e] + 1] if dp2[e][e] >= 0
  end

  until q.empty?
    a,b,v = q.shift
    if dp2.chmax(a,b,v)
      dp1.chmax(a,v)
      dp1.chmax(b,v)
    end
  end
end

s = S[-1]
puts [base + dp2[s][s] + 1, base + dp1.max].max
