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)

a, b, x = gets.split.map(&:to_i)

MAX = 10 ** 9

def calc(a, b, n)
  a * n + b * n.to_s.length
end

if x < calc(a, b, 1)
  puts 0
  exit
elsif calc(a, b, MAX) < x
  puts MAX
  exit
end

min = 1
n = MAX
max = MAX

loop do
  if calc(a, b, n) == x
    break 
  elsif calc(a, b, n) > x
    max = n
    n = (min + n) / 2
  elsif calc(a, b, n) < x
    min = n
    n = (max + n) / 2
  end

  if min - max == 1
    break
  end
end

puts n