use std::collections::HashMap; fn main() { let mut xx = String::new(); std::io::Read::read_to_string(&mut std::io::stdin(), &mut xx).ok(); let xx: Vec = xx.split_whitespace().skip(1).flat_map(str::parse).collect(); let mut xx_sorted = xx.clone(); xx_sorted.retain(|&n| n > 4); xx_sorted.sort_unstable(); xx_sorted.dedup(); let xx_sorted = xx_sorted; let n_max = *xx.iter().max().unwrap(); let mut values = HashMap::new(); values.extend([(1, 0), (2, 0), (3, 0), (4, 1)]); let mut t = (0, 0, 0, 1); let mut i_xx = 0; for i in 5..=n_max { t = (t.1, t.2, t.3, (t.0 + t.1 + t.2 + t.3) % 17); if i == xx_sorted[i_xx] { values.insert(i, t.3); i_xx += 1; } } for &n in &xx { println!("{}", values[&n]); } }