#![allow(non_snake_case, unused_imports)] use itertools::Itertools; use proconio::{input, marker::Chars, marker::Usize1}; use std::cmp::{Reverse, max, min}; use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque}; #[allow(unused_macros)] macro_rules! d { ( $( $x:expr ),* $(,)? ) => { eprintln!( concat!( $( stringify!($x), "={:?} " ),* ), $( $x ),* ); }; } #[allow(dead_code)] fn yn(b: bool) -> &'static str { if b { "Yes" } else { "No" } } fn generate(seed: u32) -> impl FnMut() -> u32 { let mut x = seed; let mut y = 1; let mut z = 2; let mut w = 3; move || { let t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); w } } fn main() { input! { seed: u32, } const SIZE: usize = 10_000_001; let k = SIZE / 2; let mut lo: i64 = 0; let mut hi: i64 = u32::MAX as i64; let mut res = hi; while lo <= hi { let m = lo.midpoint(hi); let cnt = std::iter::repeat_with(generate(seed)) .take(SIZE) .filter(|&x| x as i64 <= m) .count(); if cnt > k { hi = m - 1; res = res.min(m); } else { lo = m + 1; } } println!("{}", res); }