users, data, userlist = Array.new(101){[]}, [], {}
arr = []
gets.to_i.times{
    u, ope, d = gets.chomp.split
    u = u.to_i
    d = d.to_i
    userlist[u] = true
    case ope
    when "lock" then data[d] = u
    when "wait" then arr << [u, d]
    end
}
arr.each{|u, d| users[u] << data[d]}

deadlock = false
userlist.keys.each{|u|
    list = users[u].dup
    list2 = users[u].dup
    while true
        list3 = []
        list2.each{|u2|
            users[u2].each{|u3|
                if u3 == u
                    deadlock = true
                    break
                end
                unless list.include? u3
                    list << u3
                    list3 << u3
                end
            }
            break if deadlock
        }
        break if deadlock
        break if list3.empty?
        list2 = list3
    end
    break if deadlock
}
puts deadlock ? 1 : 0
