use std::io; use std::io::prelude::*; use std::io::BufReader; fn calc_primes(n: u32) -> Vec { let mut sieve = vec![true; (n + 1) as usize]; let max = (n as f64).sqrt() as u32; for i in 2..(max + 1) { if sieve[i as usize] { let mut j = i * 2; while j <= n { sieve[j as usize] = false; j += i; } } } let mut primes: Vec = vec![]; for (i, &s) in sieve.iter().enumerate().skip(2) { if s { primes.push(i as u32); } } primes } fn calc(args: &Vec) -> bool { let n: u32 = args[0].parse().unwrap(); let mut primes = calc_primes(n); primes.reverse(); let mut memo = vec![None; (n + 1) as usize]; rec(n, true, &primes, &mut memo) } fn rec(n: u32, turn: bool, primes: &Vec, memo: &mut Vec>) -> bool { let winner: bool; if n == 0 || n == 1 { winner = true; } else { winner = match memo[n as usize] { Some(winner) => winner, None => rec_call(n, turn, primes, memo) } } memo[n as usize] = Some(winner); !(winner ^ turn) } fn rec_call(n: u32, turn: bool, primes: &Vec, memo: &mut Vec>) -> bool { for &p in primes.iter().skip_while(|&&p| p > n) { if rec(n - p, !turn, primes, memo) == turn { return true; } } false } fn run(args: &Vec) -> Vec { if calc(args) { vec!["Win".to_string()] } else { vec!["Lose".to_string()] } } fn main() { let args = lines(BufReader::new(io::stdin())); for line in run(&args) { println!("{}", line); } } fn lines(reader: BufReader) -> Vec { reader.lines().map(|l| l.unwrap()).collect() }