Problem:
Problem F: MLE
ICPC World Finals 4日目
暗い嵐の夜だった。 夢の中でティー氏はタイムスリップしていた。
ICPCの会場のようだが何かおかしい…。 もしや…これは、N年前（Nは自然数）のICPCなのか…? 混乱の内に競技は開始してしまった。
だが慌てる必要はない。 きっと問題も簡単に違いない。 例えばこれなどはソートするだけで解けてしまうはずではないか。
冷静にコードを書き上げ、速やかにSubmit。
しかしその結果は…Memory Limit Exceeded…?!
問題
C++言語については以下のコード
long long int a[n];
unsigned long long int x = x0;
for (int i = 0; i < n; i++) {
  a[i]=(long long int)x;
  x ^= x << 13;
  x ^= x >> 7;
  x ^= x << 17;
}
Java言語については以下のコード
long[] a = new long[n];
long x = x0;
for(int i = 0; i < n; i++){
  a[i] = x;
  x ^= x << 13;
  x ^= x >>> 7;
  x ^= x << 17;
}
で与えられる擬似乱数列\( a[0], a[1], \cdots, a[n-1] \)を昇順にソートする。 \(k\)番目の数（\(
a[k-1] \)）を答えよ。
入力
n k x0
1行目に 擬似乱数列の長さ\(n\)、 求めるインデックス\(k\)、 コード中の初期値\(x0\) が空白区切りで与えられる。
出力
問題文にて定義された擬似乱数列において\(k\)番目に小さい数を1行に出力せよ。
制約
\( 0 \leq x0 \leq 9 \)
\( 1 \leq n \leq 10^{8}(= 100000000) \)
\( 1 \leq k \leq n \)
入出力例
入力1
20 10 1
出力1
-768720241707614171
この入力において生成される数列は以下の通りである。
1
1082269761
1152992998833853505
-7269227409276787159
-768720241707614171
-8787613929710185883
-670945072575735807
-6753709453369041295
-4166779903597258483
9024654201992055039
8332670729032836398
2074683623940568804
-1176172910426220663
5632491372296299238
-8006175397324373085
-8536891001451786268
-3486562341448986757
1956468987595729445
-6260278484400246991
1076885984028793263
入力2
1000000 100 2
出力2
-9221458681145860019
入力3
100000000 10000000 3
出力3
-7379326796154077070

Submitted solutions:

code_snippet: // C++20
#include <bits/stdc++.h>
using namespace std;

using u64 = unsigned long long;
using u32 = unsigned int;

static inline u64 next_xorshift(u64 &x) {
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
    return x;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    u32 n, k;
    u64 x0;
    if (!(cin >> n >> k >> x0)) return 0;

    const u64 MSB = 1ULL << 63;

    // 64bit を 22,21,21 に分割（最大バケット 2^22 = 4194304 → 約16MB）
    int parts[3] = {22, 21, 21};
    int used = 0;                 // これまでに確定した上位ビット数
    u64 prefix = 0;               // ここまでに確定した上位部分（used ビット）
    u64 kk = k;                   // 1-based の順位

    for (int pass = 0; pass < 3; ++pass) {
        int B = parts[pass];
        if (pass == 2) B = 64 - used;         // 念のため 64 に合わせる
        const size_t buckets = 1ULL << B;
        vector<u32> cnt(buckets, 0);          // 出現回数（n ≤ 1e8 なので 32bit で十分）
        const u64 maskB = (B == 64 ? ~0ULL : ((1ULL << B) - 1));
        const int shift = 64 - (used + B);    // 右シフト量（上位 used+B を取り出す）

        // 1 パス走査：列を保存せず、条件を満たすものだけ B ビット先読みしてカウント
        u64 x = x0;
        for (u32 i = 0; i < n; ++i) {
            u64 y = (x ^ MSB);                // 符号付き順序 → 符号なし順序
            u64 z = (shift ? (y >> shift) : y); // 上位 used+B ビット
            if (used == 0 || (z >> B) == prefix) {
                cnt[(u32)(z & maskB)]++;
            }
            next_xorshift(x);                 // 次の乱数へ
        }

        // 累積して k が属するバケットを特定
        u64 acc = 0;
        u64 chosen = 0;
        for (; chosen < buckets; ++chosen) {
            u64 nxt = acc + cnt[chosen];
            if (kk <= nxt) break;
            acc = nxt;
        }
        kk -= acc;                            // 選ばれたバケット内での順位に更新
        prefix = (prefix << B) | chosen;      // 上位ビット列を拡張
        used += B;
    }

    // ここまでで y の 64bit が全て確定
    u64 yk = prefix;
    u64 xk = yk ^ MSB;                        // 元のビット列へ戻す
    long long ans = (long long)xk;            // C++ の long long で出力

    cout << ans << '\n';
    return 0;
}
accuracy: 1
time_ms: 1300
memory_kb: 19812
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    long long n, k, x0;
    cin >> n >> k >> x0;
    
    // 大きなサンプリングサイズで精度を向上
    const long long SAMPLE_SIZE = 1000000;
    vector<long long> samples;
    samples.reserve(SAMPLE_SIZE);
    
    unsigned long long x = x0;
    
    if (n <= SAMPLE_SIZE) {
        // 全ての値を格納できる場合
        for (long long i = 0; i < n; i++) {
            samples.push_back((long long)x);
            x ^= x << 13;
            x ^= x >> 7;
            x ^= x << 17;
        }
    } else {
        // 等間隔サンプリング
        long long interval = n / SAMPLE_SIZE;
        for (long long i = 0; i < n; i++) {
            long long val = (long long)x;
            x ^= x << 13;
            x ^= x >> 7;
            x ^= x << 17;
            
            if (i % interval == 0) {
                samples.push_back(val);
            }
        }
    }
    
    // サンプルをソート
    sort(samples.begin(), samples.end());
    
    if (n <= SAMPLE_SIZE) {
        // 正確な答え
        cout << samples[k - 1] << endl;
    } else {
        // 近似的な答え
        long long sample_k = (long long)((double)(k - 1) * (samples.size() - 1) / (n - 1));
        sample_k = max(0LL, min(sample_k, (long long)samples.size() - 1));
        cout << samples[sample_k] << endl;
    }
    
    return 0;
}
accuracy: 0.07142857142857142
time_ms: 270
memory_kb: 11240
final_rank: 20

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

int cnt[1<<20] = {};

// bucket method
int main(){
    int n, k, x0;
    cin >> n >> k >> x0;
    if(x0 == 0){
        cout << 0 << endl;
        return 0;
    }
    unsigned long long int x = x0;
    for (int i = 0; i < n; i++) {
        ll tmp = (long long int)x;
        cnt[(1<<19)+(tmp>>44)]++;
        x ^= x << 13;
        x ^= x >> 7;
        x ^= x << 17;
    }
    int key = 0;
    for(key = 0; key < 1<<20; key++){
        if(k-cnt[key] <= 0) break;
        k -= cnt[key];
    }
    x = x0;
    vector<ll> v;
    for (int i = 0; i < n; i++) {
        ll tmp = (long long int)x;
        if((1<<19)+(tmp>>44) == key)    v.push_back(tmp);
        x ^= x << 13;
        x ^= x >> 7;
        x ^= x << 17;
    }
    sort(v.begin(), v.end());
    cout << v[k-1] << endl;
    return 0;
}
accuracy: 1
time_ms: 360
memory_kb: 7268
final_rank: 5

code_snippet: #include <string>
#include <vector>
#include <iostream>
#include <queue>
#include <functional>
#include <algorithm>
#include <random>
#include <cmath>
#include <climits>
long long int shift_next(unsigned long long int n) {
	n ^= n << 13;
	n ^= n >> 7;
	n ^= n << 17;
	return n;
}

int main() {
	constexpr int shift = 16;
	constexpr int unshift = 64 - shift;
	std::vector<int> count(1 << (shift + 1), 0);
	int n, k, x0; std::cin >> n >> k >> x0;
	if (x0 == 0) {
		std::cout << 0 << std::endl;
		return 0;
	}
	long long int x = x0;
	for (auto i = 0; i < n; ++i) {
		count[(x >> unshift) + (1 << shift)]++;
		x = shift_next(x);
	}
	auto head = 0;;
	for (; head < count.size() && count[head] < k; ++head) {
		count[head + 1] += count[head];
	}
	auto rest = k;
	if (head != 0) rest -= count[head - 1];
	std::vector<long long int> suspects;
	x = x0;
	for (auto i = 0; i < n; ++i) {
		if (head == ((x >> unshift) + (1 << shift))) suspects.push_back(x);
		x = shift_next(x);
	}
	std::sort(suspects.begin(), suspects.end());
	std::cout << suspects[rest - 1] << std::endl;
}
accuracy: 1
time_ms: 380
memory_kb: 3200
final_rank: 1

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 		9223372036854775807
#define DIVISOR      10000000000000000


int main(){

	ull count[2000];

	for(int i = 0; i < 2000; i++)count[i] = 0;

	ull N,K;
	ull x_0;
	scanf("%lld %lld %lld",&N,&K,&x_0);
	if(x_0 == 0){
		printf("0\n");
		return 0;
	}

	ull x = x_0;
	for(int i = 0; i < N; i++){
		count[(ull)(NUM+(ll)x)/DIVISOR]++;
		x ^= x << 13;
		x ^= x >> 7;
		x ^= x << 17;
	}

	int sum = 0;
	ull loc;

	for(ull i = 0; i < 2000; i++){
		if(sum+count[i] >= K){
			loc = i;
			break;
		}
		sum += count[i];
	}

	vector<ll> V;

	x = x_0;
	for(int i = 0; i < N; i++){

		if(loc == (ull)(NUM+(ll)x)/DIVISOR){
			V.push_back(x);
		}
		x ^= x << 13;
		x ^= x >> 7;
		x ^= x << 17;
	}

	sort(V.begin(),V.end());

	printf("%lld\n",V[(K-sum)-1]);

	return 0;
}
accuracy: 1
time_ms: 360
memory_kb: 3544
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
typedef unsigned long long ULL;
ULL x;
inline void setseed(int x0){x = x0;}
inline ULL getrand(){
    ULL ret = x^(1llu<<63);
    x ^=x<<13;
    x ^=x>>7;
    x ^=x<<17;
    return ret;
}

const int B = 1<<22;
int cnt[B+2];
inline void latte(){
    REP(i,B+2)cnt[i]=0;
}
#define MASK1(x) (x>>42)
#define MASK2(x) ((x<<22)>>42)
#define MASK3(x) ((x<<44)>>44)

int main(){
    int x0,n,k;
    ULL m1,m2;
    cin>>n>>k>>x0;
    latte();
    setseed(x0);
    REP(i,n)cnt[1+MASK1(getrand())]++;
    REP(i,B){
        if(cnt[i+1]>=k){
            m1 = i;
            k -= cnt[i];
            break;
        }
        cnt[i+2]+=cnt[i+1];
    }
    latte();
    setseed(x0);
    REP(i,n){
        ULL y = getrand();
        if(MASK1(y)==m1)
            cnt[1+MASK2(y)]++;
    }
    REP(i,B){
        if(cnt[i+1]>=k){
            m2 = i;
            k -= cnt[i];
            break;
        }
        cnt[i+2]+=cnt[i+1];
    }
    latte();
    setseed(x0);
    REP(i,n){
        ULL y = getrand();
        if(MASK1(y)==m1&&MASK2(y)==m2)
            cnt[1+MASK3(y)]++;
    }
    REP(i,B){
        if(cnt[i+1]>=k){
            cout<<(LL)((1llu<<63)^(m1<<42)^(m2<<20)^(ULL)i)<<endl;
            return 0;
        }
        cnt[i+2]+=cnt[i+1];
    }
    

    return 0;
}
accuracy: 1
time_ms: 1410
memory_kb: 19600
final_rank: 9

code_snippet: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back

ll bucket[1<<16];

int main() {
	int n,k,x0;
	cin>>n>>k>>x0;
	k--;
	
	if(x0==0){
		cout<<0<<endl;
		return 0;
	}

	ull x = x0;
	rep(i,n){
		bucket[uint16_t((x>>(64-16)) + (1<<15))]++;
		x ^= x<<13;
		x ^= x>>7;
		x ^= x<<17;
	}

	ll key;
	for(key=0;k-bucket[key]>=0;key++){
		k-=bucket[key];
	}

	vector<ll> v;
	x = x0;
	rep(i,n){
		if(uint16_t((x>>(64-16)) + (1<<15))==key){
			v.pb(x);
		}
		x ^= x<<13;
		x ^= x>>7;
		x ^= x<<17;
	}

	sort(all(v));
	cout<<v[k]<<endl;
}
accuracy: 1
time_ms: 410
memory_kb: 3704
final_rank: 3

code_snippet: #include "bits/stdc++.h"
using namespace std;
const long long int SP = 8192;
int main() {
	long long int N, K;long long int  X0; cin >> N >> K >> X0;
	if (!X0)cout << 0 << endl;
	else {
		unsigned long long int x = X0;
		if (N < 1e6) {

			vector<long long int>nums(N);
			for (int i = 0; i < N; ++i) {
				long long int ax = static_cast<long long int>(x);
				nums[i] = ax;
				x ^= x << 13;
				x ^= x >> 7;
				x ^= x << 17;
			}
			sort(nums.begin(), nums.end());
			cout << nums[K - 1] << endl;
		}
		else {
			int num = static_cast<int>(K * SP / N);
			int minnum = max(0, num - 32);
			int maxnum = min(static_cast<int>(SP), num + 32);
			vector<long long int>nums;
			int lower = 0;
			for (int i = 0; i < N; ++i) {
				long long int ax = static_cast<long long int>(x);
				long long int d = -(LLONG_MAX)+(ULLONG_MAX / SP * minnum);
				long long int u = -(LLONG_MAX)+(ULLONG_MAX / SP * maxnum);
				if (maxnum == SP)u = LLONG_MAX;
				if (minnum == 0)d = -LLONG_MAX;
				if (ax < d) {
					lower++;
				}
				else if (ax <= u) {
					nums.push_back(ax);
				}

				x ^= x << 13;
				x ^= x >> 7;
				x ^= x << 17;
			}

			sort(nums.begin(), nums.end());
			if (0 > K - 1 - lower || K - 1 - lower >= nums.size())cout << 0 << endl;
			else {

				cout << nums[K - 1 - lower] << endl;
			}
		}
	}

	return 0;
}
accuracy: 1
time_ms: 440
memory_kb: 11256
final_rank: 6

code_snippet: #include "bits/stdc++.h"
using namespace std;
const long long int SP = 8192;
int main() {
	long long int N, K;long long int  X0; cin >> N >> K >> X0;
	unsigned long long int x = X0;
	if (N < 5e6) {

		vector<long long int>nums(N);
		for (int i = 0; i < N; ++i) {
			long long int ax = static_cast<long long int>(x);
			nums[i] = ax;
			x ^= x << 13;
			x ^= x >> 7;
			x ^= x << 17;
		}
		sort(nums.begin(), nums.end());
		cout << nums[K - 1] << endl;
	}
	else {
		int num = static_cast<int>(K * SP / N);
		int minnum = max(0, num - 62);
		int maxnum = min(static_cast<int>(SP), num + 62);
		vector<long long int>nums;
		int lower = 0;
		for (int i = 0; i < N; ++i) {
			long long int ax = static_cast<long long int>(x);
			long long int d =  -(LLONG_MAX)+ (ULLONG_MAX / SP * minnum) ;
			long long int u =  - (LLONG_MAX)+(ULLONG_MAX / SP * maxnum);
			if (maxnum == SP)u = LLONG_MAX;
			if (minnum == 0)d = -LLONG_MAX;
			if (ax < d) {
				lower++;
			}
			else if (ax <= u) {
				nums.push_back(ax);
			}

			x ^= x << 13;
			x ^= x >> 7;
			x ^= x << 17;
		}

		sort(nums.begin(), nums.end());
		
			cout << nums[K - 1 - lower] << endl;
		
	}
	return 0;
}
accuracy: 0.10714285714285714
time_ms: 280
memory_kb: 19200
final_rank: 18

code_snippet: #include "bits/stdc++.h"
using namespace std;
const long long int SP = 8192;
int main() {
	long long int N, K;long long int  X0; cin >> N >> K >> X0;
	unsigned long long int x = X0;
	if (N < 5e6) {

		vector<long long int>nums(N);
		for (int i = 0; i < N; ++i) {
			long long int ax = static_cast<long long int>(x);
			nums[i] = ax;
			x ^= x << 13;
			x ^= x >> 7;
			x ^= x << 17;
		}
		sort(nums.begin(), nums.end());
		cout << nums[K - 1] << endl;
	}
	else {
		int num = static_cast<int>(K * SP / N);
		int minnum = max(0, num - 62);
		int maxnum = min(static_cast<int>(SP), num + 62);
		vector<long long int>nums;
		int lower = 0;
		for (int i = 0; i < N; ++i) {
			long long int ax = static_cast<long long int>(x);
			long long int d =  -(LLONG_MAX)+ (ULLONG_MAX / SP * minnum) ;
			long long int u =  - (LLONG_MAX)+(ULLONG_MAX / SP * maxnum);
			if (maxnum == SP)u = LLONG_MAX;
			if (minnum == 0)d = -LLONG_MAX;
			if (ax < d) {
				lower++;
			}
			else if (ax <= u) {
				nums.push_back(ax);
			}

			x ^= x << 13;
			x ^= x >> 7;
			x ^= x << 17;
		}

		sort(nums.begin(), nums.end());
		cout << nums[K - 1-lower] << endl;
	}
	return 0;
}
accuracy: 0.10714285714285714
time_ms: 290
memory_kb: 19184
final_rank: 19

code_snippet: #include "bits/stdc++.h"
using namespace std;
const long long int SP = 8192;
int main() {
	long long int N, K;long long int  X0; cin >> N >> K >> X0;
	unsigned long long int x = X0;
	if (N < 5e6) {

		vector<long long int>nums(N);
		for (int i = 0; i < N; ++i) {
			long long int ax = static_cast<long long int>(x);
			nums[i] = ax;
			x ^= x << 13;
			x ^= x >> 7;
			x ^= x << 17;
		}
		sort(nums.begin(), nums.end());
		cout << nums[K - 1] << endl;
	}
	else {
		int num = static_cast<int>(K * SP / N);
		int minnum = max(0, num - 22);
		int maxnum = min(static_cast<int>(SP), num + 22);
		vector<long long int>nums;
		int lower = 0;
		for (int i = 0; i < N; ++i) {
			long long int ax = static_cast<long long int>(x);
			long long int d =  -(LLONG_MAX)+ (ULLONG_MAX / SP * minnum) ;
			long long int u =  - (LLONG_MAX)+(ULLONG_MAX / SP * maxnum);
			if (maxnum == SP)u = LLONG_MAX;
			if (minnum == 0)d = -LLONG_MAX;
			if (ax < d) {
				lower++;
			}
			else if (ax <= u) {
				nums.push_back(ax);
			}

			x ^= x << 13;
			x ^= x >> 7;
			x ^= x << 17;
		}

		sort(nums.begin(), nums.end());
		cout << nums[K - 1-lower] << endl;
	}
	return 0;
}
accuracy: 0.10714285714285714
time_ms: 230
memory_kb: 11208
final_rank: 16

code_snippet: #include "bits/stdc++.h"
using namespace std;
const int SP = 8192;
int main() {
	long long int N, K;long long int  X0; cin >> N >> K >> X0;
	unsigned long long int x = X0;
	if (N < 5e6) {

		vector<long long int>nums(N);
		for (int i = 0; i < N; ++i) {
			long long int ax = static_cast<long long int>(x);
			nums[i] = ax;
			x ^= x << 13;
			x ^= x >> 7;
			x ^= x << 17;
		}
		sort(nums.begin(), nums.end());
		cout << nums[K - 1] << endl;
	}
	else {
		int num = K * SP / N;
		int minnum = max(0, num - 22);
		int maxnum = min(SP, num + 22);
		vector<long long int>nums;
		int lower = 0;
		for (int i = 0; i < N; ++i) {
			long long int ax = static_cast<long long int>(x);
			long long int d =  -(LLONG_MAX)+ (ULLONG_MAX / SP * minnum) ;
			long long int u =  - (LLONG_MAX)+(ULLONG_MAX / SP * maxnum);
			if (maxnum == SP)u = LLONG_MAX;
			if (minnum == 0)d = -LLONG_MAX;
			if (ax < d) {
				lower++;
			}
			else if (ax <= u) {
				nums.push_back(ax);
			}

			x ^= x << 13;
			x ^= x >> 7;
			x ^= x << 17;
		}

		sort(nums.begin(), nums.end());
		cout << nums[K - 1-lower] << endl;
	}
	return 0;
}
accuracy: 0.10714285714285714
time_ms: 230
memory_kb: 11040
final_rank: 13

code_snippet: #include "bits/stdc++.h"
using namespace std;
const int SP = 8192;
int main() {
	long long int N, K;long long int  X0; cin >> N >> K >> X0;
	unsigned long long int x = X0;
	if (N < 1e6) {

		vector<long long int>nums(N);
		for (int i = 0; i < N; ++i) {
			long long int ax = static_cast<long long int>(x);
			nums[i] = ax;
			x ^= x << 13;
			x ^= x >> 7;
			x ^= x << 17;
		}
		sort(nums.begin(), nums.end());
		cout << nums[K - 1] << endl;
	}
	else {
		int num = K * SP / N;
		int minnum = max(0, num - 22);
		int maxnum = min(SP, num + 22);
		vector<long long int>nums;
		int lower = 0;
		for (int i = 0; i < N; ++i) {
			long long int ax = static_cast<long long int>(x);
			long long int d =  -(LLONG_MAX)+ (ULLONG_MAX / SP * minnum) ;
			long long int u =  - (LLONG_MAX)+(ULLONG_MAX / SP * maxnum);
			if (maxnum == SP)u = LLONG_MAX;
			if (minnum == 0)d = -LLONG_MAX;
			if (ax < d) {
				lower++;
			}
			else if (ax <= u) {
				nums.push_back(ax);
			}

			x ^= x << 13;
			x ^= x >> 7;
			x ^= x << 17;
		}

		sort(nums.begin(), nums.end());
		cout << nums[K - 1-lower] << endl;
	}
	return 0;
}
accuracy: 0.10714285714285714
time_ms: 230
memory_kb: 11160
final_rank: 15

code_snippet: #include "bits/stdc++.h"
using namespace std;
const int SP = 8192;
int main() {
	long long int N, K;long long int  X0; cin >> N >> K >> X0;
	unsigned long long int x = X0;
	if (N < 1e6) {

		vector<long long int>nums(N);
		for (int i = 0; i < N; ++i) {
			long long int ax = static_cast<long long int>(x);
			nums[i] = ax;
			x ^= x << 13;
			x ^= x >> 7;
			x ^= x << 17;
		}
		sort(nums.begin(), nums.end());
		cout << nums[K - 1] << endl;
	}
	else {
		int num = K * SP / N;
		int minnum = max(0, num - 22);
		int maxnum = min(SP, num + 22);
		vector<long long int>nums;
		int lower = 0;
		for (int i = 0; i < N; ++i) {
			long long int ax = static_cast<long long int>(x);
			long long int u =  -(LLONG_MAX)+ (ULLONG_MAX / SP * minnum) -1;
			long long int d =  - (LLONG_MAX)+(ULLONG_MAX / SP * maxnum) - 1;
			if (maxnum == SP)d = LLONG_MAX;
			if (minnum == 0)u = -LLONG_MAX;
			if (ax <= u) {
				lower++;
			}
			else if (ax <= d) {
				nums.push_back(ax);
			}

			x ^= x << 13;
			x ^= x >> 7;
			x ^= x << 17;
		}

		sort(nums.begin(), nums.end());
		cout << nums[K - 1-lower] << endl;
	}
	return 0;
}
accuracy: 0.10714285714285714
time_ms: 230
memory_kb: 11140
final_rank: 14

code_snippet: #include "bits/stdc++.h"
using namespace std;
const int SP = 8192;
int main() {
	long long int N, K;long long int  X0; cin >> N >> K >> X0;
	unsigned long long int x = X0;
	if (N < 1e6) {

		vector<long long int>nums(N);
		for (int i = 0; i < N; ++i) {
			long long int ax = static_cast<long long int>(x);
			nums[i] = ax;
			x ^= x << 13;
			x ^= x >> 7;
			x ^= x << 17;
		}
		sort(nums.begin(), nums.end());
		cout << nums[K - 1] << endl;
	}
	else {
		int num = K * SP / N;
		int minnum = max(0, num - 22);
		int maxnum = min(SP, num + 22);
		vector<long long int>nums;
		int lower = 0;
		for (int i = 0; i < N; ++i) {
			long long int ax = static_cast<long long int>(x);
			long long int u =  -(LLONG_MAX)+ (ULLONG_MAX / SP * minnum) -1;
			long long int d =  - (LLONG_MAX)+(ULLONG_MAX / SP * maxnum) - 1;
			if (ax <= u) {
				lower++;
			}
			else if (ax <= d) {
				nums.push_back(ax);
			}

			x ^= x << 13;
			x ^= x >> 7;
			x ^= x << 17;
		}

		sort(nums.begin(), nums.end());
		cout << nums[K - 1-lower] << endl;
	}
	return 0;
}
accuracy: 0.10714285714285714
time_ms: 240
memory_kb: 11168
final_rank: 17

code_snippet: #include "bits/stdc++.h"
using namespace std;
const int SP = 8192;
int main() {
	long long int N, K;long long int  X0; cin >> N >> K >> X0;
	unsigned long long int x = X0;
	if (N < 1e6) {

		vector<long long int>nums(N);
		for (int i = 0; i < N; ++i) {
			long long int ax = static_cast<long long int>(x);
			nums[i] = ax;
			x ^= x << 13;
			x ^= x >> 7;
			x ^= x << 17;
		}
		sort(nums.begin(), nums.end());
		cout << nums[K - 1] << endl;
	}
	else {
		int num = K * SP / N;
		int minnum = max(0, num - 5);
		int maxnum = min(SP, num + 5);
		vector<long long int>nums;
		int lower = 0;
		for (int i = 0; i < N; ++i) {
			long long int ax = static_cast<long long int>(x);
			long long int u =  -(LLONG_MAX)+ (ULLONG_MAX / SP * minnum) -1;
			long long int d =  - (LLONG_MAX)+(ULLONG_MAX / SP * maxnum) - 1;
			if (ax <= u) {
				lower++;
			}
			else if (ax <= d) {
				nums.push_back(ax);
			}

			x ^= x << 13;
			x ^= x >> 7;
			x ^= x << 17;
		}

		sort(nums.begin(), nums.end());
		cout << nums[K - 1-lower] << endl;
	}
	return 0;
}
accuracy: 0.10714285714285714
time_ms: 200
memory_kb: 3824
final_rank: 11

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define BOX 1000000000000000LL
const int WID = 10000;
long long n, k, l; unsigned long long p, q;
vector<long long>vec;
long long sum[WID * 10];
int main() {
	cin >> n >> k >> p; q = p;
	if (p == 0) { cout << "0" << endl; return 0; }
	for (int i = 0; i < n; i++) {
		long long r = p;
		long long L = r / BOX; if (r < 0LL)L--;
		sum[L + WID]++;
		p ^= p << 13; p ^= p >> 7; p ^= p << 17;
	}
	for (int i = 1; i <= WID * 2; i++) sum[i] += sum[i - 1];
	for (int i = 0; i < WID * 2; i++) { if (sum[i] >= k) { l = i - WID; break; } }
	for (int i = 0; i < n; i++) {
		long long K = (long long)q / BOX; if ((long long)q < 0)K--;
		if (l == K) vec.push_back((long long)q);
		q ^= q << 13; q ^= q >> 7; q ^= q << 17;
	}
	sort(vec.begin(), vec.end());
	cout << vec[k - sum[l + WID - 1] - 1] << endl;
	return 0;
}
accuracy: 1
time_ms: 470
memory_kb: 3392
final_rank: 4

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define BOX 100000000000000000LL
const int WID = 100;
long long n, k, l; unsigned long long p, q;
vector<long long>vec;
long long sum[WID * 10];
int main() {
	cin >> n >> k >> p; q = p;
	if (p == 0) { cout << "0" << endl; return 0; }
	for (int i = 0; i < n; i++) {
		long long r = p;
		long long L = r / BOX; if (r < 0LL)L--;
		sum[L + WID]++;
		p ^= p << 13; p ^= p >> 7; p ^= p << 17;
	}
	for (int i = 1; i <= WID * 2; i++) sum[i] += sum[i - 1];
	for (int i = 0; i < WID * 2; i++) { if (sum[i] >= k) { l = i - WID; break; } }
	for (int i = 0; i < n; i++) {
		long long K = (long long)q / BOX; if ((long long)q < 0)K--;
		if (l == K) vec.push_back((long long)q);
		q ^= q << 13; q ^= q >> 7; q ^= q << 17;
	}
	sort(vec.begin(), vec.end());
	cout << vec[k - sum[l + WID - 1] - 1] << endl;
	return 0;
}
accuracy: 1
time_ms: 450
memory_kb: 11260
final_rank: 7

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
#define BOX 10000000000000000LL
#define WID 2000
long long n, k, l; unsigned long long p, q;
map<long long, long long>sum;
vector<long long>vec;
long long sum2[WID * 10];
int main() {
	cin >> n >> k >> p; q = p; k--;
	if (p == 0) { cout << "0" << endl; return 0; }
	for (int i = 0; i < n; i++) {
		sum2[WID + (long long)p / BOX]++;
		p ^= p << 13; p ^= p >> 7; p ^= p << 17;
	}
	for (int i = 0; i <= WID * 2; i++) { sum[i - WID] = sum2[i]; }
	for (int i = -WID; i <= WID; i++) sum[i] += sum[i - 1];
	for (int i = WID; i >= -WID; i--) { if (sum[i] <= k) { l = i; break; } }
	for (int i = 0; i < n; i++) {
		long long K = (long long)q / BOX; if ((long long)q < 0)K--;
		if (l == K) vec.push_back((long long)q);
		q ^= q << 13; q ^= q >> 7; q ^= q << 17;
	}
	sort(vec.begin(), vec.end());
	cout << vec[k - sum[l]] << endl;
	return 0;
}
accuracy: 0.14285714285714285
time_ms: 420
memory_kb: 3796
final_rank: 10

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
#define BOX 10000000000000000LL
#define WID 2000
long long n, k, l; unsigned long long p, q;
map<long long, long long>sum;
vector<long long>vec;
long long sum2[WID * 10];
int main() {
	cin >> n >> k >> p; q = p; k--;
	for (int i = 0; i < n; i++) {
		sum2[WID + (long long)p / BOX]++;
		p ^= p << 13; p ^= p >> 7; p ^= p << 17;
	}
	for (int i = 0; i <= WID * 2; i++) { sum[i - WID] = sum2[i]; }
	for (int i = -WID; i <= WID; i++) sum[i] += sum[i - 1];
	for (int i = WID; i >= -WID; i--) { if (sum[i] <= k) { l = i; break; } }
	for (int i = 0; i < n; i++) {
		long long K = (long long)q / BOX; if ((long long)q < 0)K--;
		if (l == K) vec.push_back((long long)q);
		q ^= q << 13; q ^= q >> 7; q ^= q << 17;
	}
	sort(vec.begin(), vec.end());
	cout << vec[k - sum[l]] << endl;
	return 0;
}
accuracy: 0.10714285714285714
time_ms: 420
memory_kb: 3800
final_rank: 12