There are n noobs in the team, the i-th of which has a rating ai. sd0061 prepares one hint for each contest. The hint for the j-th contest is a number bj, which means that the noob with the (bj+1)-th lowest rating is ordained by sd0061 for the j-th contest.
The coach asks constroy to make a list of contestants. constroy looks into these hints and finds out: bi+bj≤bk is satisfied if bi≠bj, bi<bk and bj<bk.
Now, you are in charge of making the list for constroy.
For each test case:
The first line contains five integers n,m,A,B,C. (1≤n≤107,1≤m≤100)
The second line contains m integers, the i-th of which is the number bi of the i-th hint. (0≤bi<n)
The n noobs' ratings are obtained by calling following function n times, the i-th result of which is ai.
unsigned x = A, y = B, z = C;
unsigned rng61() {
unsigned t;
x ^= x << 16;
x ^= x >> 5;
x ^= x << 1;
t = x;
x = y;
y = z;
z = t ^ x ^ y;
return z;
}
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int N=1e7+;
unsigned x,y,z, A,B,C;
unsigned a[N];
struct Node
{
int x;
int id;
unsigned y;
}tr[];
bool cmp(const Node s1,const Node s2)
{
return s1.x<s2.x;
}
bool cmp2(const Node s1,const Node s2)
{
return s1.id<s2.id;
} unsigned rng61() {
unsigned t;
x ^= x << ;
x ^= x >> ;
x ^= x << ;
t = x;
x = y;
y = z;
z = t ^ x ^ y;
return z;
} int main()
{
///cout << "Hello world!" << endl;
int n,m,Case=1;
while(scanf("%d%d%u%u%u",&n,&m,&A,&B,&C)!=EOF)
{
x = A, y = B, z = C;
for(int i=;i<n;i++) a[i]=rng61();
printf("Case #%d:",Case++);
for(int i=;i<=m;i++) scanf("%d",&tr[i].x),tr[i].id=i;
sort(tr+,tr+m+,cmp); int p=n;
for(int i=m;i>=;i--)
{
int x = tr[i].x;
nth_element(a,a+x,a+p);
p=x;
tr[i].y=a[x];
}
sort(tr+,tr+m+,cmp2);
for(int i=;i<=m;i++) printf(" %u",tr[i].y);
puts("");
}
return ;
}