
fun main(args:Array<String>):Unit {
    loop@while(true){
        val n = readLine()!!.trim().toInt()
        if (n == 0) return
        val relation = Array(n){
            val rel = readLine()!!.trim().split(' ')
            Triple(rel[1], rel[3].split('^').last().toInt(), rel.last())
        }
        val map = mutableMapOf<String, UnionFindTree>()
        for (i in 0 until n) {
            val (left, diff, right) = relation[i]
            if (map.getOrPut(left, { UnionFindTree() }).isNotParadoxical(map.getOrPut(right, { UnionFindTree() }), diff))
                map[left]!!.merge(map[right]!!, diff)
            else{
                println("No")
                continue@loop
            }
        }
        println("Yes")

    }
}
class UnionFindTree{
    private var mParent:UnionFindTree? = null
    private var mPosition:Int = 0
    private fun parent():Pair<Int, UnionFindTree> {
        return when(mParent){
            null -> Pair(0, this)
            else -> {
                val (d, p) = mParent!!.parent()
                mPosition += d
                mParent = p
                Pair(mPosition, p)
            }
        }
    }
    fun isNotParadoxical(other:UnionFindTree, differ:Int):Boolean {
        val (td, tp) = parent()
        val (od, op) = other.parent()
        return (tp != op) || (od + differ == td)
    }
    fun merge(other:UnionFindTree, differ:Int):Unit {
        if (isNotParadoxical(other, differ)){
            val (td, tp) = parent()
            val (od, op) = other.parent()
            if (tp != op){
                tp.mParent = op
                tp.mPosition = od - td + differ
            }
        }
    }
}
