// yukicoder: No. 702 中央値を求めよ LIMITED // 2019.5.5 bal4u #include unsigned x = 0, y = 1, z = 2, w = 3; unsigned generate() { unsigned t = x^(x<<11); x = y, y = z, z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); return w; } unsigned selection(unsigned *a, int sz, int n) { int i, j, l, r; unsigned p, t; l = 0, r = sz-1; while (l < r) { p = a[(l+r)/2]; i = l-1, j = r+1; while (1) { while (a[++i] < p); while (a[--j] > p); if (i > j) break; t = a[i], a[i] = a[j], a[j] = t; } if (n < i) r = j; if (n > j) l = i; } return a[n]; } #define SIZE 10000001 #define UPPER (unsigned)2150000000 #define LOWER (unsigned)2146000000 unsigned a[UPPER-LOWER+10000]; int sz; int main() { int i, cnt; unsigned k; scanf("%u", &x); sz = 0, cnt = 0; i = SIZE; while (i--) { k = generate(); if (k <= LOWER) cnt++; else if (k < UPPER) a[sz++] = k; } printf("%u\n", selection(a, sz, (SIZE >> 1)-cnt)); return 0; }