# Your code here!
@A = 10
@B = 7
@X = 100
@maxPow = 9

def priceOf(number)
    @A * number + @B * number.to_i.to_s.length
end

#絞り込みの定義
def narrow(start, prefix)
    array = (0..10).map{|i| start.to_f + i.to_f/prefix}
    under = array.filter{|i| priceOf(10**i) <= @X}.max
    top = array.filter{|i| priceOf(10**i) >= @X}.min
    return [under, top]
end

#小数点以下3桁くらいまで絞れば行けそう
numlog10_1 = narrow(0,1)
numlog10_10 = narrow(numlog10_1[0],10)
numlog10_100 = narrow(numlog10_10[0],100)
numlog10_1000 = narrow(numlog10_100[0],1000)

#下限が存在しない=購入できない
if numlog10_1000[0].nil?
    puts "NONE"
    return
end

#上限が存在しない=すべて購入できる
if numlog10_1000[1].nil?
    puts "ALL"
    return
end

first = (10**numlog10_1000[0]).to_i
last = (10**numlog10_1000[1]).to_i+1

answer = (first..last).filter{|i| priceOf(i) <= @X}.max

puts "answer:#{answer}"
puts "answerの価格:#{priceOf(answer)}"
puts "answer+1の価格:#{priceOf(answer+1)}"