import scala.collection.mutable

object Main extends App {
  import scala.io.StdIn._


  val n = readInt
  val program = new Program(Array.tabulate(n){_ ⇒ readLine.trim})
  executeWhileEnd(program)
  def executeWhileEnd(program: Program): Unit = {
    val single: State = new State
    val double: State = new State
    double.execute(program)
    while(!double.isEnded && single != double) {
      single.execute(program)
      double.execute(program)
      double.execute(program)
    }
    if (double.isEnded) {
      println(program.allVariables.sorted.map(name ⇒ s"$name=${double.read(name)}").mkString("\n"))
    }
    else println("inf")
  }

  class Program(state: Array[String]) {
    private[this] val set: mutable.Set[String] = new mutable.TreeSet[String]()
    private[this] val statementByLine = Array.tabulate(1001){_ ⇒ -1000}
    private[this] val statements = state.zipWithIndex.map{case (s, i) ⇒
       s.split(' ') match {
        case Array(line, "ADD", dest, variable, constant) if constant.head.isDigit ⇒
          statementByLine(line.toInt) = i
          set.add(dest)
          set.add(variable)
          Add(line.toInt, Variable(dest), Variable(variable), Constant(constant.toInt))
        case Array(line, "ADD", dest, left, right) ⇒
          statementByLine(line.toInt) = i
          set.add(dest)
          set.add(left)
          set.add(right)
          Add(line.toInt, Variable(dest), Variable(left), Variable(right))
        case Array(line, "SUB", dest, variable, constant) if constant.head.isDigit ⇒
          statementByLine(line.toInt) = i
          set.add(dest)
          set.add(variable)
          Sub(line.toInt, Variable(dest), Variable(variable), Constant(constant.toInt))
        case Array(line, "SUB", dest, left, right) ⇒
          statementByLine(line.toInt) = i
          set.add(dest)
          set.add(left)
          set.add(right)
          Sub(line.toInt, Variable(dest), Variable(left), Variable(right))
        case Array(line, "SET", dest, constant) if constant.head.isDigit ⇒
          statementByLine(line.toInt) = i
          set.add(dest)
          Set(line.toInt, Variable(dest), Constant(constant.toInt))
        case Array(line, "SET", dest, variable) ⇒
          statementByLine(line.toInt) = i
          set.add(dest)
          set.add(variable)
          Set(line.toInt, Variable(dest), Variable(variable))
        case Array(line, "IF", variable, dest) ⇒
          statementByLine(line.toInt) = i
          set.add(variable)
          Jump(line.toInt, Variable(variable), dest.toInt)
        case Array(line, "HALT") ⇒
          statementByLine(line.toInt) = i
          Halt
      }
    }
    def allVariables: Seq[String] = set.toSeq
    def headLine: Statement = statements.head
    def nextLine(currentLine: Int): Int = {
      if (statementByLine.indices.contains(currentLine) && statements.indices.contains(statementByLine(currentLine) + 1)) statements(statementByLine(currentLine) + 1).line
      else -1
    }
    def readStatement(currentLine: Int): Statement = {
      if (statementByLine.indices.contains(currentLine) && statements.indices.contains(statementByLine(currentLine))) statements(statementByLine(currentLine))
      else Halt
    }
  }
  sealed trait Statement{
    def line: Int
  }
  case object Halt extends Statement{
    override val line: Int = -1
  }
  case class Add(line: Int, dest: Variable, left: Variable, right: Token) extends Statement
  case class Sub(line: Int, dest: Variable, left: Variable, right: Token) extends Statement
  case class Set(line: Int, dest: Variable, right: Token) extends Statement
  case class Jump(line: Int, obj: Variable, dest: Int) extends Statement

  sealed trait Token
  case class Constant(value: Int) extends Token
  case class Variable(name: String) extends Token
  object State{
    case class Var(name: String, var value: Int) {
      def tryWriteValue(newValue: Int): Boolean = {
        if (newValue >= 16 || newValue < 0) false
        else {
          value = newValue
          true
        }
      }
    }
    class Memory {
      private var inner: List[Var] = Nil
      private[this] def confirmVariable(name: String): Var = {
        inner.find(_.name == name) match {
          case Some(v) ⇒ v
          case None ⇒
            val res = Var(name, 0)
            inner ::= res
            res
        }
      }
      def read(name: String): Int = {
        confirmVariable(name).value
      }
      def isDefined(name: String): Boolean = {
        inner.exists(_.name == name)
      }
      def tryWrite(name: String, value: Int): Boolean = {
        confirmVariable(name).tryWriteValue(value)
      }
      def show: String = inner.sortBy(_.name).map(v ⇒ s"${v.name}=${v.value}").mkString("\n")
      override def equals(obj: Any): Boolean = {
        obj match {
          case that: Memory ⇒ that.inner.foldLeft(0)((a, b) ⇒ a * 16 + b.value) == inner.foldLeft(0)((a, b) => a * 16 + b.value)
          case _ ⇒ super.equals(obj)
        }
      }
    }
  }
  class State {
    private val memory = new State.Memory()
    private var currentLine: Int = -1000
    private var end = false
    override def equals(obj: Any): Boolean = {
      obj match {
        case that: State ⇒
          currentLine == that.currentLine && end == that.end && memory == that.memory
        case _ ⇒
          super.equals(obj)
      }
    }
    def show: String = {
      memory.show
    }
    def read(name: String): Int = {
      if (memory.isDefined(name)) memory.read(name)
      else 0
    }
    def isEnded: Boolean = end
    def execute(program: Program): Unit = {
      if (end) return
      val statement = if (currentLine == -1000) program.headLine
      else program.readStatement(currentLine)
      currentLine = program.nextLine(statement.line)
      statement match {
        case Halt ⇒
          end = true
        case Add(_, Variable(dest), Variable(left), Variable(right)) ⇒
          val value = memory.read(left)
          end = !memory.tryWrite(dest, value + memory.read(right))
        case Add(_, Variable(dest), Variable(right), Constant(value)) ⇒
          end = !memory.tryWrite(dest, value + memory.read(right))
        case Sub(_, Variable(dest), Variable(left), Variable(right)) ⇒
          val value = memory.read(left)
          end = !memory.tryWrite(dest, (value - memory.read(right)).toChar)
        case Sub(_, Variable(dest), Variable(right), Constant(value)) ⇒
          end = !memory.tryWrite(dest, memory.read(right) - value)
        case Set(_, Variable(dest), Variable(right)) ⇒
          end = !memory.tryWrite(dest, memory.read(right))
        case Set(_, Variable(dest), Constant(value)) ⇒
          end = !memory.tryWrite(dest, value)
        case Jump(_, Variable(obj), dest) ⇒
          if (memory.read(obj) != 0) currentLine = dest
      }
    }
  }

  implicit class Scope[T](val value: T) extends AnyVal{
    @inline
    def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline
    def let[A](func: T ⇒ A): A = func(value)
  }
}



Measured memory_bytes: 102020