const val MAX_WEIGHT = 100
const val MAX_DP_J = 10000
interface Interaction {
val N: Int
val dp: List<IntArray>
fun ask(i: Int, j: Int): Int
}
class LocalInteraction() : Interaction {
override val N: Int = readLine()!!.toInt()
override val dp: List<IntArray>
val asked = List(N+1) { BooleanArray(MAX_DP_J + 1) }
init {
val W = readLine()!!.split(" ").map{ it.toInt() }
val P = readLine()!!.split(" ").map{ it.toInt() }
dp = List(N+1) { IntArray(MAX_DP_J+1) }
for(i in 0 until N) {
for(j in 0 .. MAX_DP_J) {
if(j < W[i]) dp[i+1][j] = dp[i][j]
else dp[i+1][j] = maxOf(dp[i][j],dp[i][j-W[i]]+P[i])
}
}
}
override fun ask(i: Int, j: Int): Int {
println
("asked ${i} ${j} ${if(!asked[i][j]) "for the first
time" else "again
"}") asked[i][j] = true
return dp[i][j]
}
}
class RealInteraction : Interaction {
override val N: Int = readLine()!!.toInt()
override val dp: List<IntArray> = List(N+1) { IntArray(MAX_DP_J+1) { -1 } }
override fun ask(i: Int, j: Int): Int {
if(dp[i][j] < 0) {
println("1 ${i} ${j}")
dp[i][j] = readLine()!!.toInt()
}
return dp[i][j]
}
}
fun binarySearchOnWeight(predicate: (Int) -> Boolean): Int {
// returns minimum `it` where `predicate(it)` is true
var low = 1
var high = MAX_WEIGHT
var ret = -1
while(low <= high) {
val mid = (low + high) / 2
if(predicate(mid)) {
ret = mid
high = mid-1
}else {
low = mid+1
}
}
return ret
}
fun main(args: Array<String>) {
if(args.isNotEmpty()) {
System.setIn(java.io.FileInputStream(args[0]))
}
val interaction = if(args.isNotEmpty()) LocalInteraction() else RealInteraction()
val N = interaction.N
require(N in 1..100)
val W = IntArray(N+1)
val P = IntArray(N+1)
// step 1: find W[1], P[1]
W[1] = binarySearchOnWeight { interaction.ask(1, it) > 0 }
P[1] = interaction.ask(1, W[1])
// step 2: compute others
for(i in 2..N) {
val sumOfProfitsUntilNow = interaction.ask(i, MAX_DP_J)
P[i] = sumOfProfitsUntilNow - P.slice(1 until i).sum()
val sumOfWeightsBefore = W.slice(1 until i).sum()
W[i] = binarySearchOnWeight { interaction.ask(i, it + sumOfWeightsBefore) >= sumOfProfitsUntilNow }
}
println(2)
println(W.drop(1).toList().joinToString(" "))
println(P.drop(1).toList().joinToString(" "))
}