


data class MInt(val value: Long) {
    operator fun plus(that: MInt): MInt {
        return MInt((value + that.value) % MOD)
    }
    operator fun minus(that: MInt): MInt {
        return MInt(((value - that.value) % MOD + MOD) % MOD)
    }
    operator fun times(that: MInt): MInt {
        return MInt(value * that.value % MOD)
    }
    operator fun div(that: MInt): MInt {
        return this * power(that, MOD - 2)
    }
    companion object {
        private fun power(base: MInt, exp: Long): MInt {
            return when(exp) {
                0L -> One
                1L -> base
                else -> power(base * base, exp shr 1) * power(base, exp and 1)
            }
        }
        val MOD = 2147483659L
        val One = MInt(1L)
    }
}
fun Long.toMInt(): MInt {
    val value = this
    return when{
        value >= 0 -> MInt(value)
        else -> MInt(MInt.MOD + value)
    }
}
data class MInt2(val value: Long) {
    operator fun plus(that: MInt2): MInt2 {
        return MInt2((value + that.value) % MOD)
    }
    operator fun minus(that: MInt2): MInt2 {
        return MInt2(((value - that.value) % MOD + MOD) % MOD)
    }
    operator fun times(that: MInt2): MInt2 {
        return MInt2(value * that.value % MOD)
    }
    operator fun div(that: MInt2): MInt2 {
        return this * power(that, MOD - 2)
    }
    companion object {
        private fun power(base: MInt2, exp: Long): MInt2 {
            return when(exp) {
                0L -> One
                1L -> base
                else -> power(base * base, exp shr 1) * power(base, exp and 1)
            }
        }
        val MOD = 2147483693L
        val One = MInt2(1L)
    }
}
fun Long.toMInt2(): MInt2 {
    val value = this
    return when {
        value >= 0 -> MInt2(value)
        else -> MInt2(MInt2.MOD + value)
    }
}
fun main(args: Array<String>) {
    val ops = List(readLine()!!.trim().toInt()){
            val (op, y) = readLine()!!.trim().split(' ').map(String::toInt)
            op to y.toLong()
        }
    val ops1 = arrayOf(MInt::plus, MInt::minus, MInt::times, MInt::div)
    val res1 = ops.fold(MInt(0)){acc, (op, y) ->
        //println(acc)
        ops1[op - 1](acc, y.toMInt())
    }
    val ops2 = arrayOf(MInt2::plus, MInt2::minus, MInt2::times, MInt2::div)
    val res2 = ops.fold(MInt2(0)){acc, (op, y) ->
        //println(acc)
        ops2[op - 1](acc, y.toMInt2())
    }
    when {
        res1.value == res2.value ->
            println(res1.value)
        res1.value - MInt.MOD == res2.value - MInt2.MOD ->
            println(res1.value - MInt.MOD)
        else -> throw NotImplementedError()

    }
}

