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 Rust (1.15.1) (judge verdict: Runtime Error)

use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn digits(mut num: i64) -> i64 {
    let mut count: i64 = 0;

    if num == 0 {
        return 1
    }
    
    while num != 0 {
        num /= 10;
        count += 1;
    }

    count
}

fn price(n: i64, a: i64, b: i64) -> i64 {
    (a * n) + (b * digits(n))
}

fn main() {
    let (a, b, x): (i64, i64, i64) = (read(), read(), read());
    let mut begin: i64 = 0;
    let mut end: i64 = 10_i64.pow(9);
    let mut n: i64 = (begin + end) / 2;


    if x > price(n, a, b) {
        println!("{}", end);
        return ()
    } else if x < price(0, a, b) {
        println!("{}", 0);
        return ()
    }
    
    while 1 < (begin - end).abs() {
        let p = price(n, a, b);
        let diff = (end - begin) / 2;

        if p > x {
            end = n;
        } else if p < x {
            begin = n;
        }
        
        n = (begin + end) / 2;
    }

    println!("{}", begin);
    
}