import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string; auto rdsp(){return readln.splitter;} void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;} void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);} const n = 10000001; void main() { uint seed; readV(seed); auto b = new int[](1<<16); init(seed); foreach (_; 0..n) { auto a = generate(); ++b[a>>16]; } auto i = 0, s = 0; while (i < 1<<16) { if (s+b[i] >= (n+1)/2) break; s += b[i++]; } b[] = 0; init(seed); foreach (_; 0..n) { auto a = generate(); if ((a>>16) == i) ++b[a&((1<<16)-1)]; } foreach (j; 0..1<<16) { s += b[j]; if (s >= (n+1)/2) { writeln((i<<16)|j); return; } ++j; } } class CumulativeSum(T) { size_t n; T[] s; this(T[] a) { n = a.length; s = new T[](n+1); s[0] = T(0); foreach (i; 0..n) s[i+1] = s[i] + a[i]; } T opSlice(size_t l, size_t r) { return s[r]-s[l]; } size_t opDollar() { return n; } } auto cumulativeSum(T)(T[] a) { return new CumulativeSum!T(a); } uint x = 0, y = 1, z = 2, w = 3; void init(uint seed) { x = seed; y = 1; z = 2; w = 3; } uint generate() { uint t = (x^(x<<11)); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); return w; }