#![allow(unused_imports)] #![allow(non_snake_case)] use proconio::input; use proconio::marker::*; use std::cmp::*; use std::collections::*; fn main() { let months = 12; let days1 = 9; let days2 = 3; let result = solve(months, days2, days1); println!("{}", result); } fn solve(months: usize, tens_digit: usize, ones_digit: usize) -> usize { let mut count = 0; for month in 1..=months { for tens in 0..=tens_digit { if month == 2 && tens > 2 { continue; } for ones in 0..=ones_digit { if tens == 0 && ones == 0 { continue; } if !is_valid(month, tens, ones) { continue; } if tens + ones == month { count += 1; } } } } count } fn is_valid(month: usize, tens: usize, ones: usize) -> bool { match tens { 3 => { if [4, 6, 9, 11].contains(&month) { return false; } if ones > 1 { return false; } } 2 => { if month == 2 && ones > 8 { return false; } } _ => {} } true }