Problem:
Score : 100 points

Problem Statement

Given is a string S representing the day of the week today.

S is SUN, MON, TUE, WED, THU, FRI, or SAT, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively.

After how many days is the next Sunday (tomorrow or later)?

Constraints

S is SUN, MON, TUE, WED, THU, FRI, or SAT.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of days before the next Sunday.

Sample Input 1

SAT

Sample Output 1

1

It is Saturday today, and tomorrow will be Sunday.

Sample Input 2

SUN

Sample Output 2

7

It is Sunday today, and seven days later, it will be Sunday again.

Solution in Ruby (2.3.3) (judge verdict: Runtime Error)

# 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)}"