loop do
  n = gets.to_i
  break if n == 0
  start = {}
  bless = Hash.new(0)
  n.times do
    gets =~ /^(\d\d)\/(\d\d) (\d\d):(\d\d) (.) (\d\d\d)/
    # p [$1.to_i, $2.to_i, $3.to_i, $4.to_i, $5, $6.to_i]
    t = $3.to_i * 60 + $4.to_i
    io = $5
    p = $6.to_i
    if io == ?I
      start[p] = t
    elsif p == 0
      start_g = start[0]
      start.delete(0)
      start.each do |q, start_q|
        bless[q] += t - [start_g, start_q].max
      end
    else
      start_p = start[p]
      start.delete(p)
      start_g = start[0]
      bless[p] += t - [start_g, start_p].max if start_g
    end
  end
  p bless.values.max || 0
end

