#include<bits/stdc++.h>
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FOR2(i,a,b) for(i=a;i<b;i++)
#define IFOR(i,a,b) for(i=a;i>=b;i--)
#define IFOR2(i,a,b) for(i=a;i>b;i--)
#define IND(a) scanf("%d",&a)
#define IND2(a,b) scanf("%d%d",&a,&b)
#define IND3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define INL(a) scanf("%I64d",&a)
#define INL2(a,b) scanf("%I64d%I64d",&a,&b)
#define INL3(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)
#define INS(s) scanf("%s",&s)
#define OUTD(a) printf("%d ",a)
#define OUTD2(a,b) printf("%d %d ",a,b)
#define OUTD3(a,b,c) printf("%d %d %d",a,b,c)
#define pb push_back
#define OUTL(a) printf("%I64d ",a)
#define ll long long
using namespace std;
const int nm=100005;
const int mm=100005;
int n,k,m,t,d,x,dem;
int a[nm],b[nm],vt[nm],q[nm];
bool check[nm];
int getNextX() {
    x = (x * 37ll + 10007) % 1000000007;
    return x;
}
void initAB() {
    int i;
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
    FOR2(i,0,n) if(b[i]) q[++dem]=i;
}
main(){
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    #endif
    int i,j,y,z,w,Max;
    IND3(n,d,x);
    initAB();
    if(dem<1000){
        FOR2(i,0,n){
            Max=0;
            for(j=1;j<=dem && q[j]<=i;j++)
                if(a[i-q[j]]>Max) Max=a[i-q[j]];
            printf("%d\n",Max);
        }
    }else{
        FOR(i,1,n) vt[a[i]]=i;
        FOR2(i,0,n){
            for(j=n;j>0;j--){
                if(vt[j]<=i && b[i-vt[j]]){
                    printf("%d\n",j);
                    break;
                }
            }
            if(j==0) printf("0\n");
        }
    }
}


#include<bits/stdc++.h>
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FOR2(i,a,b) for(i=a;i<b;i++)
#define IFOR(i,a,b) for(i=a;i>=b;i--)
#define IFOR2(i,a,b) for(i=a;i>b;i--)
#define IND(a) scanf("%d",&a)
#define IND2(a,b) scanf("%d%d",&a,&b)
#define IND3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define INL(a) scanf("%I64d",&a)
#define INL2(a,b) scanf("%I64d%I64d",&a,&b)
#define INL3(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)
#define INS(s) scanf("%s",&s)
#define OUTD(a) printf("%d ",a)
#define OUTD2(a,b) printf("%d %d ",a,b)
#define OUTD3(a,b,c) printf("%d %d %d",a,b,c)
#define pb push_back
#define OUTL(a) printf("%I64d ",a)
#define ll long long
using namespace std;
const int nm=100005;
const int mm=100005;
int n,k,m,t,d,x,dem;
int a[nm],b[nm],vt[nm],q[nm];
bool check[nm];
int getNextX() {
    x = (x * 37ll + 10007) % 1000000007;
    return x;
}
void initAB() {
    int i;
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
    FOR2(i,0,n) if(b[i]) q[++dem]=i;
}
main(){
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    #endif
    int i,j,y,z,w,Max;
    IND3(n,d,x);
    initAB();
    if(dem<5000){
        FOR2(i,0,n){
            Max=0;
            for(j=1;j<=dem && q[j]<=i;j++)
                if(a[i-q[j]]>Max) Max=a[i-q[j]];
            printf("%d\n",Max);
        }
    }else{
        FOR(i,1,n) vt[a[i]]=i;
        FOR2(i,0,n){
            for(j=n;j>0;j--){
                if(vt[j]<=i && b[i-vt[j]]){
                    printf("%d\n",j);
                    break;
                }
            }
            if(j==0) printf("0\n");
        }
    }
}


#include<bits/stdc++.h>
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FOR2(i,a,b) for(i=a;i<b;i++)
#define IFOR(i,a,b) for(i=a;i>=b;i--)
#define IFOR2(i,a,b) for(i=a;i>b;i--)
#define IND(a) scanf("%d",&a)
#define IND2(a,b) scanf("%d%d",&a,&b)
#define IND3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define INL(a) scanf("%I64d",&a)
#define INL2(a,b) scanf("%I64d%I64d",&a,&b)
#define INL3(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)
#define INS(s) scanf("%s",&s)
#define OUTD(a) printf("%d ",a)
#define OUTD2(a,b) printf("%d %d ",a,b)
#define OUTD3(a,b,c) printf("%d %d %d",a,b,c)
#define pb push_back
#define OUTL(a) printf("%I64d ",a)
#define ll long long
using namespace std;
const int nm=100005;
const int mm=100005;
int n,k,m,t,d,x,dem;
int a[nm],b[nm],vt[nm],q[nm];
bool check[nm];
int getNextX() {
    x = (x * 37ll + 10007) % 1000000007;
    return x;
}
void initAB() {
    int i;
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
    FOR2(i,0,n) if(b[i]) q[++dem]=i;
}
main(){
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    #endif
    int i,j,y,z,w,Max;
    IND3(n,d,x);
    initAB();
    if(dem<4000){
        FOR2(i,0,n){
            Max=0;
            for(j=1;j<=dem && q[j]<=i;j++)
                if(a[i-q[j]]>Max) Max=a[i-q[j]];
            printf("%d\n",Max);
        }
    }else{
        FOR(i,1,n) vt[a[i]]=i;
        FOR2(i,0,n){
            for(j=n;j>0;j--){
                if(vt[j]<=i && b[i-vt[j]]){
                    printf("%d\n",j);
                    break;
                }
            }
            if(j==0) printf("0\n");
        }
    }
}


#include<bits/stdc++.h>
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FOR2(i,a,b) for(i=a;i<b;i++)
#define IFOR(i,a,b) for(i=a;i>=b;i--)
#define IFOR2(i,a,b) for(i=a;i>b;i--)
#define IND(a) scanf("%d",&a)
#define IND2(a,b) scanf("%d%d",&a,&b)
#define IND3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define INL(a) scanf("%I64d",&a)
#define INL2(a,b) scanf("%I64d%I64d",&a,&b)
#define INL3(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)
#define INS(s) scanf("%s",&s)
#define OUTD(a) printf("%d ",a)
#define OUTD2(a,b) printf("%d %d ",a,b)
#define OUTD3(a,b,c) printf("%d %d %d",a,b,c)
#define pb push_back
#define OUTL(a) printf("%I64d ",a)
#define ll long long
using namespace std;
const int nm=100005;
const int mm=100005;
int n,k,m,t,d,x,dem;
int a[nm],b[nm],vt[nm],q[nm];
bool check[nm];
int getNextX() {
    x = (x * 37ll + 10007) % 1000000007;
    return x;
}
void initAB() {
    int i;
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
    FOR2(i,0,n) if(b[i]) q[++dem]=i;
}
main(){
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    #endif
    int i,j,y,z,w,Max;
    IND3(n,d,x);
    initAB();
    if(dem<1500){
        FOR2(i,0,n){
            Max=0;
            for(j=1;j<=dem && q[j]<=i;j++)
                if(a[i-q[j]]>Max) Max=a[i-q[j]];
            printf("%d\n",Max);
        }
    }else{
        FOR(i,1,n) vt[a[i]]=i;
        FOR2(i,0,n){
            for(j=n;j>0;j--){
                if(vt[j]<=i && b[i-vt[j]]){
                    printf("%d\n",j);
                    break;
                }
            }
            if(j==0) printf("0\n");
        }
    }
}


#include<bits/stdc++.h>
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FOR2(i,a,b) for(i=a;i<b;i++)
#define IFOR(i,a,b) for(i=a;i>=b;i--)
#define IFOR2(i,a,b) for(i=a;i>b;i--)
#define IND(a) scanf("%d",&a)
#define IND2(a,b) scanf("%d%d",&a,&b)
#define IND3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define INL(a) scanf("%I64d",&a)
#define INL2(a,b) scanf("%I64d%I64d",&a,&b)
#define INL3(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)
#define INS(s) scanf("%s",&s)
#define OUTD(a) printf("%d ",a)
#define OUTD2(a,b) printf("%d %d ",a,b)
#define OUTD3(a,b,c) printf("%d %d %d",a,b,c)
#define pb push_back
#define OUTL(a) printf("%I64d ",a)
#define ll long long
using namespace std;
const int nm=100005;
const int mm=100005;
int n,k,m,t,d,x,dem;
int a[nm],b[nm],vt[nm],q[nm];
bool check[nm];
int getNextX() {
    x = (x * 37ll + 10007) % 1000000007;
    return x;
}
void initAB() {
    int i;
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
    FOR2(i,0,n) if(b[i]) q[++dem]=i;
}
main(){
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    #endif
    int i,j,y,z,w,Max;
    IND3(n,d,x);
    initAB();
    if(dem<500){
        FOR2(i,0,n){
            Max=0;
            for(j=1;j<=dem && q[j]<=i;j++)
                if(a[i-q[j]]>Max) Max=a[i-q[j]];
            printf("%d\n",Max);
        }
    }else{
        FOR(i,1,n) vt[a[i]]=i;
        FOR2(i,0,n){
            for(j=n;j>0;j--){
                if(vt[j]<=i && b[i-vt[j]]){
                    printf("%d\n",j);
                    break;
                }
            }
            if(j==0) printf("0\n");
        }
    }
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int nm=100005;
int n,k,m,t,d,x,dem;
int a[nm],b[nm],vt[nm],q[nm];
int getNextX() {
    x = ((ll)x * 37 + 10007) % 1000000007;
    return x;
}
main(){
    int i,j,y,z,w,Max;
    scanf("%d%d%d",&n,&d,&x);
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
    for(i=0;i<n;i++) if(b[i]) q[++dem]=i;
    if(dem<1000){
        for(i=0;i<n;i++){
            Max=0;
            for(j=1;j<=dem && q[j]<=i;j++)
                if(a[i-q[j]]>Max) Max=a[i-q[j]];
            printf("%d\n",Max);
        }
    }else{
        for(i=1;i<n;i++) vt[a[i]]=i;
        for(i=0;i<n;i++){
            for(j=n;j>0;j--){
                if(vt[j]<=i && b[i-vt[j]]){
                    printf("%d\n",j);
                    break;
                }
            }
            if(j==0) printf("0\n");
        }
    }
}


#include<bits/stdc++.h>
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FOR2(i,a,b) for(i=a;i<b;i++)
#define IFOR(i,a,b) for(i=a;i>=b;i--)
#define IFOR2(i,a,b) for(i=a;i>b;i--)
#define IND(a) scanf("%d",&a)
#define IND2(a,b) scanf("%d%d",&a,&b)
#define IND3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define INL(a) scanf("%I64d",&a)
#define INL2(a,b) scanf("%I64d%I64d",&a,&b)
#define INL3(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)
#define INS(s) scanf("%s",&s)
#define OUTD(a) printf("%d ",a)
#define OUTD2(a,b) printf("%d %d ",a,b)
#define OUTD3(a,b,c) printf("%d %d %d",a,b,c)
#define pb push_back
#define OUTL(a) printf("%I64d ",a)
#define ll long long
using namespace std;
const int nm=100005;
const int mm=100005;
int n,k,m,t,d,x,dem;
int a[nm],b[nm],vt[nm],q[nm];
bool check[nm];
int getNextX() {
    x = (x * 37ll + 10007) % 1000000007;
    return x;
}
void initAB() {
    int i;
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
    FOR2(i,0,n) if(b[i]) q[++dem]=i;
}
main(){
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    #endif
    int i,j,y,z,w,Max;
    IND3(n,d,x);
    initAB();
    if(dem<800){
        FOR2(i,0,n){
            Max=0;
            for(j=1;j<=dem && q[j]<=i;j++)
                if(a[i-q[j]]>Max) Max=a[i-q[j]];
            printf("%d\n",Max);
        }
    }else{
        FOR(i,1,n) vt[a[i]]=i;
        FOR2(i,0,n){
            for(j=n;j>0;j--){
                if(vt[j]<=i && b[i-vt[j]]){
                    printf("%d\n",j);
                    break;
                }
            }
            if(j==0) printf("0\n");
        }
    }
}


#include <cstdio>
#include <algorithm>
#include <cmath>
#include <ctime>
using namespace std;

int n, d, X, A[110000], B[110000], q[110000], to[110000];
int pu;

int getNextX() {
    X = (X * 37LL + 10007) % 1000000007;
    return X;
}

int main() {
    scanf("%d%d%d", &n, &d, &X);
    for (int i = 0; i < n; i = i + 1)
        A[i] = i + 1;
    for (int i = 0; i < n; i = i + 1)
        swap(A[i], A[getNextX() % (i + 1)]);
    for (int i = 0; i < n; i = i + 1) {
        if (i < d)
            B[i] = 1;
        else
            B[i] = 0;
    }
    for (int i = 0; i < n; i = i + 1)
        swap(B[i], B[getNextX() % (i + 1)]);
    for (int i = 0; i < n; i++) if (B[i])   q[++q[0]] = i;

    int s = 30;

    for (int i = 0; i < n; i++) to[A[i]] = i;

    for (int i = 0; i < n; i++) {
        int j;
        for (j = n; j >= n - s; j--)
            if (j > 0 && i >= to[j] && B[i - to[j]]) {
                printf("%d\n", j);
                break;
            }
        if (j < n - s) {
            int ma = 0;
            for (j = 1; j <= q[0] && q[j] <= i; j++)
                ma = max(ma, A[i - q[j]]);
            printf("%d\n", ma);
        }
    }
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int nm=100005;
int n,k,m,t,d,x,dem;
int a[nm],b[nm],vt[nm],q[nm];
int getNextX() {
    x = (x * 37ll + 10007) % 1000000007;
    return x;
}
main(){
    int i,j,y,z,w,Max;
    scanf("%d%d%d",&n,&d,&x);
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
    for(i=0;i<n;i++) if(b[i]) q[++dem]=i;
    if(dem<1000){
        for(i=0;i<n;i++){
            Max=0;
            for(j=1;j<=dem && q[j]<=i;j++)
                if(a[i-q[j]]>Max) Max=a[i-q[j]];
            printf("%d ",Max);
        }
    }else{
        for(i=1;i<n;i++) vt[a[i]]=i;
        for(i=0;i<n;i++){
            for(j=n;j>0;j--){
                if(vt[j]<=i && b[i-vt[j]]){
                    printf("%d ",j);
                    break;
                }
            }
            if(j==0) printf("0 ");
        }
    }
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int nm=100005;
int n,k,m,t,d,x,dem;
int a[nm],b[nm],vt[nm],q[nm];
int getNextX() {
    x = ((ll)x * 37 + 10007) % 1000000007;
    return x;
}
main(){
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    #endif
    int i,j,y,z,w,Max;
    scanf("%d%d%d",n,d,x);
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
    for(i=0;i<n;i++) if(b[i]) q[++dem]=i;
    if(dem<1000){
        for(i=0;i<n;i++){
            Max=0;
            for(j=1;j<=dem && q[j]<=i;j++)
                if(a[i-q[j]]>Max) Max=a[i-q[j]];
            printf("%d\n",Max);
        }
    }else{
        for(i=1;i<n;i++) vt[a[i]]=i;
        for(i=0;i<n;i++){
            for(j=n;j>0;j--){
                if(vt[j]<=i && b[i-vt[j]]){
                    printf("%d\n",j);
                    break;
                }
            }
            if(j==0) printf("0\n");
        }
    }
}


#include<bits/stdc++.h>
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FOR2(i,a,b) for(i=a;i<b;i++)
#define IFOR(i,a,b) for(i=a;i>=b;i--)
#define IFOR2(i,a,b) for(i=a;i>b;i--)
#define IND(a) scanf("%d",&a)
#define IND2(a,b) scanf("%d%d",&a,&b)
#define IND3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define INL(a) scanf("%I64d",&a)
#define INL2(a,b) scanf("%I64d%I64d",&a,&b)
#define INL3(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)
#define INS(s) scanf("%s",&s)
#define OUTD(a) printf("%d ",a)
#define OUTD2(a,b) printf("%d %d ",a,b)
#define OUTD3(a,b,c) printf("%d %d %d",a,b,c)
#define pb push_back
#define OUTL(a) printf("%I64d ",a)
#define ll long long
using namespace std;
const int nm=100005;
const int mm=100005;
int n,k,m,t,d,x,dem;
int a[nm],b[nm],vt[nm],q[nm];
bool check[nm];
int getNextX() {
    x = (x * 37ll + 10007) % 1000000007;
    return x;
}
void initAB() {
    int i;
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
    FOR2(i,0,n) if(b[i]) q[++dem]=i;
}
main(){
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    #endif
    int i,j,y,z,w,Max;
    IND3(n,d,x);
    initAB();
    if(dem<1200){
        FOR2(i,0,n){
            Max=0;
            for(j=1;j<=dem && q[j]<=i;j++)
                if(a[i-q[j]]>Max) Max=a[i-q[j]];
            printf("%d\n",Max);
        }
    }else{
        FOR(i,1,n) vt[a[i]]=i;
        FOR2(i,0,n){
            for(j=n;j>0;j--){
                if(vt[j]<=i && b[i-vt[j]]){
                    printf("%d\n",j);
                    break;
                }
            }
            if(j==0) printf("0\n");
        }
    }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#define Maxx 100100
using namespace std;

int a[Maxx],b[Maxx],n,d;
long long x;

long long getNextX(void)
{
     x = (x * 37 + 10007) % 1000000007;
    return x;
}

void calc(void)
{
    long long i;
    for(i=0;i<n;i++)
    {
        a[i]=i+1;
    }
    for(i=0;i<n;i++)
    {
        swap(a[i],a[getNextX()%(i+1)]);
    }
    for(i=0;i<n;i++)
    {
        if(i<d)
        {
            b[i]=1;
        }
        else
        {
            b[i]=0;
        }
    }
    for(i=0;i<n;i++)
    {
        swap(b[i],b[getNextX()%(i+1)]);
    }
}

main()
{
    int i,j,k,ind,cnt=0;
    cin>>n>>d>>x;

    calc();

    int c[n];
    bool done[n],solve=true;
    fill(c,c+n,0);
    fill(done,done+n,false);
    vector<pair<int,int> > v;
    vector<int> non_zero;

    for(i=0;i<n;i++)
    {
        v.push_back(make_pair(a[i],i));
    }
    sort(v.rbegin(),v.rend());
    for(i=0;i<n;i++)
    {
        if(b[i])
        {
            non_zero.push_back(i);
        }
    }
    for(i=0;i<n&&solve;i++)
        for(j=0;j<non_zero.size()&&solve;j++)
    {
        ind=v[i].second+non_zero[j];
        if(ind>=n)
        {
            j=non_zero.size()-1;
        }
        else if(!done[ind])
        {
            c[ind]=v[i].first;
            cnt++;
            done[ind]=true;
        }
        if(cnt==n)
        {
            solve=false;
        }
    }
    for(i=0;i<n;i++)
    {
        cout<<c[i]<<endl;
    }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#define Maxx 100100
using namespace std;

int a[Maxx],b[Maxx],n,d;
long long x;

long long getNextX(void)
{
     x = (x * 37 + 10007) % 1000000007;
    return x;
}

void calc(void)
{
    long long i;
    for(i=0;i<n;i++)
    {
        a[i]=i+1;
    }
    for(i=0;i<n;i++)
    {
        swap(a[i],a[getNextX()%(i+1)]);
    }
    for(i=0;i<n;i++)
    {
        if(i<d)
        {
            b[i]=1;
        }
        else
        {
            b[i]=0;
        }
    }
    for(i=0;i<n;i++)
    {
        swap(b[i],b[getNextX()%(i+1)]);
    }
}

main()
{
    int i,j,k,ind,ele,cnt=0;
    cin>>n>>d>>x;

    calc();

    int c[n];
    bool done[n],solve=true;
    fill(c,c+n,0);
    fill(done,done+n,false);
    vector<pair<int,int> > v;
    vector<int> non_zero,remain;
    set<int> nz;
    set<int>::iterator fnd;

    for(i=0;i<n;i++)
    {
        v.push_back(make_pair(a[i],i));
    }
    sort(v.rbegin(),v.rend());
    for(i=0;i<n;i++)
    {
        if(b[i])
        {
            non_zero.push_back(i);
            nz.insert(i);
        }
    }

    for(i=0;i<non_zero[0];i++)
    {
        done[i]=true;
        cnt++;
    }

    k=-1;
    for(i=0;i<n&&solve;i++)
        for(j=0;j<non_zero.size()&&solve;j++)
    {
        ind=v[i].second+non_zero[j];
        if(ind>=n)
        {
            j=non_zero.size()-1;
        }
        else if(!done[ind])
        {
            c[ind]=v[i].first;
            cnt++;
            done[ind]=true; //if(ind<50)cout<<ind<<endl;
        }
        if(n-cnt<10)
        {
            k=i;
            solve=false;
        }
    }

    for(i=0;i<n;i++)
    {
        if(!done[i])
        {
            remain.push_back(i);
        }
    }

        for(i=k;i<n&&cnt!=n;i++)
        {
            for(j=0;j<remain.size()&&cnt!=n;j++)
            {
                ele=remain[j];
                if(done[ele]) continue;
                ind=ele-v[i].second;
                if(ind>=0)
                {
                    fnd=nz.lower_bound(ind);
                    if(fnd!=nz.end())
                    {
                        if(*fnd==ind)
                        {
                            c[ele]=v[i].first;
                            cnt++;
                            done[ele]=true;
                        }
                    }
                }
            }
        }

    for(i=0;i<n;i++)
    {
        printf("%d\n",c[i]);
    }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#define Maxx 100100
using namespace std;

int a[Maxx],b[Maxx],n,d;
long long x;

long long getNextX(void)
{
     x = (x * 37 + 10007) % 1000000007;
    return x;
}

void calc(void)
{
    long long i;
    for(i=0;i<n;i++)
    {
        a[i]=i+1;
    }
    for(i=0;i<n;i++)
    {
        swap(a[i],a[getNextX()%(i+1)]);
    }
    for(i=0;i<n;i++)
    {
        if(i<d)
        {
            b[i]=1;
        }
        else
        {
            b[i]=0;
        }
    }
    for(i=0;i<n;i++)
    {
        swap(b[i],b[getNextX()%(i+1)]);
    }
}

main()
{
    int i,j,k,ind,ele,cnt=0;
    cin>>n>>d>>x;

    calc();

    int c[n];
    bool done[n],solve=true;
    fill(c,c+n,0);
    fill(done,done+n,false);
    vector<pair<int,int> > v;
    vector<int> non_zero,remain;
    set<int> nz;
    set<int>::iterator fnd;

    for(i=0;i<n;i++)
    {
        v.push_back(make_pair(a[i],i));
    }
    sort(v.rbegin(),v.rend());
    for(i=0;i<n;i++)
    {
        if(b[i])
        {
            non_zero.push_back(i);
            nz.insert(i);
        }
    }

    for(i=0;i<non_zero[0];i++)
    {
        done[i]=true;
        cnt++;
    }

    k=-1;
    for(i=0;i<n&&solve;i++)
        for(j=0;j<non_zero.size()&&solve;j++)
    {
        ind=v[i].second+non_zero[j];
        if(ind>=n)
        {
            j=non_zero.size()-1;
        }
        else if(!done[ind])
        {
            c[ind]=v[i].first;
            cnt++;
            done[ind]=true; //if(ind<50)cout<<ind<<endl;
        }
        if(n-cnt<250)
        {
            k=i;
            solve=false;
        }
    }

    for(i=0;i<n;i++)
    {
        if(!done[i])
        {
            remain.push_back(i);
        }
    }

        for(i=k;i<n&&cnt!=n;i++)
        {
            for(j=0;j<remain.size()&&cnt!=n;j++)
            {
                ele=remain[j];
                if(done[ele]) continue;
                ind=ele-v[i].second;
                if(ind>=0)
                {
                    fnd=nz.lower_bound(ind);
                    if(fnd!=nz.end())
                    {
                        if(*fnd==ind)
                        {
                            c[ele]=v[i].first;
                            cnt++;
                            done[ele]=true;
                        }
                    }
                }
            }
        }

    for(i=0;i<n;i++)
    {
        printf("%d\n",c[i]);
    }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#define Maxx 100100
using namespace std;

int a[Maxx],b[Maxx],n,d;
long long x;

long long getNextX(void)
{
     x = (x * 37 + 10007) % 1000000007;
    return x;
}

void calc(void)
{
    long long i;
    for(i=0;i<n;i++)
    {
        a[i]=i+1;
    }
    for(i=0;i<n;i++)
    {
        swap(a[i],a[getNextX()%(i+1)]);
    }
    for(i=0;i<n;i++)
    {
        if(i<d)
        {
            b[i]=1;
        }
        else
        {
            b[i]=0;
        }
    }
    for(i=0;i<n;i++)
    {
        swap(b[i],b[getNextX()%(i+1)]);
    }
}

main()
{
    int i,j,k,ind,ele,cnt=0;
    cin>>n>>d>>x;

    calc();

    int c[n];
    bool done[n],solve=true;
    fill(c,c+n,0);
    fill(done,done+n,false);
    vector<pair<int,int> > v;
    vector<int> non_zero,remain;
    set<int> nz;
    set<int>::iterator fnd;

    for(i=0;i<n;i++)
    {
        v.push_back(make_pair(a[i],i));
    }
    sort(v.rbegin(),v.rend());
    for(i=0;i<n;i++)
    {
        if(b[i])
        {
            non_zero.push_back(i);
            nz.insert(i);
        }
    }
    k=-1;
    for(i=0;i<n&&solve;i++)
        for(j=0;j<non_zero.size()&&solve;j++)
    {
        ind=v[i].second+non_zero[j];
        if(ind>=n)
        {
            j=non_zero.size()-1;
        }
        else if(!done[ind])
        {
            c[ind]=v[i].first;
            cnt++;
            done[ind]=true;
        }
        if(n-cnt<25)
        {
            k=i;
            solve=false;
        }
    }

    for(i=0;i<n;i++)
    {
        if(!done[i])
        {
            remain.push_back(i);
        }
    }

        for(i=k;i<n&&cnt!=n;i++)
        {
            for(j=0;j<remain.size();j++)
            {
                ele=remain[j];
                if(done[ele]) continue;
                ind=ele-v[i].second;
                if(ind>=0)
                {
                    fnd=nz.lower_bound(ind);
                    if(fnd!=nz.end())
                    {
                        if(*fnd==ind)
                        {
                            c[ele]=v[i].first;
                            cnt++;
                            done[ele]=true;
                        }
                    }
                }
            }
        }

    for(i=0;i<n;i++)
    {
        printf("%d\n",c[i]);
    }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#define Maxx 100
using namespace std;

int a[Maxx],b[Maxx],n,d;
long long x;

long long getNextX(void)
{
     x = (x * 37 + 10007) % 1000000007;
    return x;
}

void calc(void)
{
    long long i;
    for(i=0;i<n;i++)
    {
        a[i]=i+1;
    }
    for(i=0;i<n;i++)
    {
        swap(a[i],a[getNextX()%(i+1)]);
    }
    for(i=0;i<n;i++)
    {
        if(i<d)
        {
            b[i]=1;
        }
        else
        {
            b[i]=0;
        }
    }
    for(i=0;i<n;i++)
    {
        swap(b[i],b[getNextX()%(i+1)]);
    }
}

main()
{
    int i,j,k,ind,cnt=0;
    cin>>n>>d>>x;

    calc();

    int c[n];
    bool done[n],solve=true;
    fill(c,c+n,0);
    fill(done,done+n,false);
    vector<pair<int,int> > v;
    vector<int> non_zero;

    for(i=0;i<n;i++)
    {
        v.push_back(make_pair(a[i],i));
    }
    sort(v.rbegin(),v.rend());
    for(i=0;i<n;i++)
    {
        if(b[i])
        {
            non_zero.push_back(i);
        }
    }
    for(i=0;i<n&&solve;i++)
        for(j=0;j<non_zero.size()&&solve;j++)
    {
        ind=v[i].second+non_zero[j];
        if(ind>=n)
        {
            j=non_zero.size()-1;
        }
        else if(!done[ind])
        {
            c[ind]=v[i].first;
            cnt++;
            done[ind]=true;
        }
        if(cnt==n)
        {
            solve=false;
        }
    }
    for(i=0;i<n;i++)
    {
        cout<<c[i]<<endl;
    }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#define Maxx 100100
using namespace std;

int a[Maxx],b[Maxx],n,d;
long long x;

long long getNextX(void)
{
     x = (x * 37 + 10007) % 1000000007;
    return x;
}

void calc(void)
{
    long long i;
    for(i=0;i<n;i++)
    {
        a[i]=i+1;
    }
    for(i=0;i<n;i++)
    {
        swap(a[i],a[getNextX()%(i+1)]);
    }
    for(i=0;i<n;i++)
    {
        if(i<d)
        {
            b[i]=1;
        }
        else
        {
            b[i]=0;
        }
    }
    for(i=0;i<n;i++)
    {
        swap(b[i],b[getNextX()%(i+1)]);
    }
}

main()
{
    int i,j,k,ind,ele,cnt=0;
    cin>>n>>d>>x;

    calc();

    int c[n];
    bool done[n],solve=true;
    fill(c,c+n,0);
    fill(done,done+n,false);
    vector<pair<int,int> > v;
    vector<int> non_zero,remain;
    set<int> nz;
    set<int>::iterator fnd;

    for(i=0;i<n;i++)
    {
        v.push_back(make_pair(a[i],i));
    }
    sort(v.rbegin(),v.rend());
    for(i=0;i<n;i++)
    {
        if(b[i])
        {
            non_zero.push_back(i);
            nz.insert(i);
        }
    }

    for(i=0;i<non_zero[0];i++)
    {
        done[i]=true;
        cnt++;
    }

    k=-1;
    for(i=0;i<n&&solve;i++)
        for(j=0;j<non_zero.size()&&solve;j++)
    {
        ind=v[i].second+non_zero[j];
        if(ind>=n)
        {
            j=non_zero.size()-1;
        }
        else if(!done[ind])
        {
            c[ind]=v[i].first;
            cnt++;
            done[ind]=true; //if(ind<50)cout<<ind<<endl;
        }
        if(n-cnt<1)
        {
            k=i;
            solve=false;
        }
    }

    for(i=0;i<n;i++)
    {
        if(!done[i])
        {
            remain.push_back(i);
        }
    }

        for(i=k;i<n&&cnt!=n;i++)
        {
            for(j=0;j<remain.size()&&cnt!=n;j++)
            {
                ele=remain[j];
                if(done[ele]) continue;
                ind=ele-v[i].second;
                if(ind>=0)
                {
                    fnd=nz.lower_bound(ind);
                    if(fnd!=nz.end())
                    {
                        if(*fnd==ind)
                        {
                            c[ele]=v[i].first;
                            cnt++;
                            done[ele]=true;
                        }
                    }
                }
            }
        }

    for(i=0;i<n;i++)
    {
        printf("%d\n",c[i]);
    }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#define Maxx 100100
using namespace std;

int a[Maxx],b[Maxx],n,d;
long long x;

long long getNextX(void)
{
     x = (x * 37 + 10007) % 1000000007;
    return x;
}

void calc(void)
{
    long long i;
    for(i=0;i<n;i++)
    {
        a[i]=i+1;
    }
    for(i=0;i<n;i++)
    {
        swap(a[i],a[getNextX()%(i+1)]);
    }
    for(i=0;i<n;i++)
    {
        if(i<d)
        {
            b[i]=1;
        }
        else
        {
            b[i]=0;
        }
    }
    for(i=0;i<n;i++)
    {
        swap(b[i],b[getNextX()%(i+1)]);
    }
}

main()
{
    int i,j,k,ind,ele,cnt=0;
    cin>>n>>d>>x;

    calc();

    int c[n];
    bool done[n],solve=true;
    fill(c,c+n,0);
    fill(done,done+n,false);
    vector<pair<int,int> > v;
    vector<int> non_zero,remain;
    set<int> nz;
    set<int>::iterator fnd;

    for(i=0;i<n;i++)
    {
        v.push_back(make_pair(a[i],i));
    }
    sort(v.rbegin(),v.rend());
    for(i=0;i<n;i++)
    {
        if(b[i])
        {
            non_zero.push_back(i);
            nz.insert(i);
        }
    }

    for(i=0;i<non_zero[0];i++)
    {
        done[i]=true;
        cnt++;
    }

    k=-1;
    for(i=0;i<n&&solve;i++)
        for(j=0;j<non_zero.size()&&solve;j++)
    {
        ind=v[i].second+non_zero[j];
        if(ind>=n)
        {
            j=non_zero.size()-1;
        }
        else if(!done[ind])
        {
            c[ind]=v[i].first;
            cnt++;
            done[ind]=true; //if(ind<50)cout<<ind<<endl;
        }
        if(n-cnt<200)
        {
            k=i;
            solve=false;
        }
    }

    for(i=0;i<n;i++)
    {
        if(!done[i])
        {
            remain.push_back(i);
        }
    }

        for(i=k;i<n&&cnt!=n;i++)
        {
            for(j=0;j<remain.size()&&cnt!=n;j++)
            {
                ele=remain[j];
                if(done[ele]) continue;
                ind=ele-v[i].second;
                if(ind>=0)
                {
                    fnd=nz.lower_bound(ind);
                    if(fnd!=nz.end())
                    {
                        if(*fnd==ind)
                        {
                            c[ele]=v[i].first;
                            cnt++;
                            done[ele]=true;
                        }
                    }
                }
            }
        }

    for(i=0;i<n;i++)
    {
        printf("%d\n",c[i]);
    }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#define Maxx 100100
using namespace std;

int a[Maxx],b[Maxx],n,d;
long long x;

long long getNextX(void)
{
     x = (x * 37 + 10007) % 1000000007;
    return x;
}

void calc(void)
{
    long long i;
    for(i=0;i<n;i++)
    {
        a[i]=i+1;
    }
    for(i=0;i<n;i++)
    {
        swap(a[i],a[getNextX()%(i+1)]);
    }
    for(i=0;i<n;i++)
    {
        if(i<d)
        {
            b[i]=1;
        }
        else
        {
            b[i]=0;
        }
    }
    for(i=0;i<n;i++)
    {
        swap(b[i],b[getNextX()%(i+1)]);
    }
}

main()
{
    int i,j,k,ind,ele,cnt=0;
    cin>>n>>d>>x;

    calc();

    int c[n];
    bool done[n],solve=true;
    fill(c,c+n,0);
    fill(done,done+n,false);
    vector<pair<int,int> > v;
    vector<int> non_zero,remain;
    set<int> nz;
    set<int>::iterator fnd;

    for(i=0;i<n;i++)
    {
        v.push_back(make_pair(a[i],i));
    }
    sort(v.rbegin(),v.rend());
    for(i=0;i<n;i++)
    {
        if(b[i])
        {
            non_zero.push_back(i);
            nz.insert(i);
        }
    }

    for(i=0;i<non_zero[0];i++)
    {
        done[i]=true;
        cnt++;
    }

    k=-1;
    for(i=0;i<n&&solve;i++)
        for(j=0;j<non_zero.size()&&solve;j++)
    {
        ind=v[i].second+non_zero[j];
        if(ind>=n)
        {
            j=non_zero.size()-1;
        }
        else if(!done[ind])
        {
            c[ind]=v[i].first;
            cnt++;
            done[ind]=true; //if(ind<50)cout<<ind<<endl;
        }
        if(n-cnt<100)
        {
            k=i;
            solve=false;
        }
    }

    for(i=0;i<n;i++)
    {
        if(!done[i])
        {
            remain.push_back(i);
        }
    }

        for(i=k;i<n&&cnt!=n;i++)
        {
            for(j=0;j<remain.size()&&cnt!=n;j++)
            {
                ele=remain[j];
                if(done[ele]) continue;
                ind=ele-v[i].second;
                if(ind>=0)
                {
                    fnd=nz.lower_bound(ind);
                    if(fnd!=nz.end())
                    {
                        if(*fnd==ind)
                        {
                            c[ele]=v[i].first;
                            cnt++;
                            done[ele]=true;
                        }
                    }
                }
            }
        }

    for(i=0;i<n;i++)
    {
        printf("%d\n",c[i]);
    }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#define Maxx 100100
using namespace std;

int a[Maxx],b[Maxx],n,d;
long long x;

long long getNextX(void)
{
     x = (x * 37 + 10007) % 1000000007;
    return x;
}

void calc(void)
{
    long long i;
    for(i=0;i<n;i++)
    {
        a[i]=i+1;
    }
    for(i=0;i<n;i++)
    {
        swap(a[i],a[getNextX()%(i+1)]);
    }
    for(i=0;i<n;i++)
    {
        if(i<d)
        {
            b[i]=1;
        }
        else
        {
            b[i]=0;
        }
    }
    for(i=0;i<n;i++)
    {
        swap(b[i],b[getNextX()%(i+1)]);
    }
}

main()
{
    int i,j,k,ind,ele,cnt=0;
    cin>>n>>d>>x;

    calc();

    int c[n];
    bool done[n],solve=true;
    fill(c,c+n,0);
    fill(done,done+n,false);
    vector<pair<int,int> > v;
    vector<int> non_zero,remain;
    set<int> nz;
    set<int>::iterator fnd;

    for(i=0;i<n;i++)
    {
        v.push_back(make_pair(a[i],i));
    }
    sort(v.rbegin(),v.rend());
    for(i=0;i<n;i++)
    {
        if(b[i])
        {
            non_zero.push_back(i);
            nz.insert(i);
        }
    }

    for(i=0;i<non_zero[0];i++)
    {
        done[i]=true;
        cnt++;
    }

    k=-1;
    for(i=0;i<n&&solve;i++)
        for(j=0;j<non_zero.size()&&solve;j++)
    {
        ind=v[i].second+non_zero[j];
        if(ind>=n)
        {
            j=non_zero.size()-1;
        }
        else if(!done[ind])
        {
            c[ind]=v[i].first;
            cnt++;
            done[ind]=true; //if(ind<50)cout<<ind<<endl;
        }
        if(n-cnt<25)
        {
            k=i;
            solve=false;
        }
    }

    for(i=0;i<n;i++)
    {
        if(!done[i])
        {
            remain.push_back(i);
        }
    }

        for(i=k;i<n&&cnt!=n;i++)
        {
            for(j=0;j<remain.size()&&cnt!=n;j++)
            {
                ele=remain[j];
                if(done[ele]) continue;
                ind=ele-v[i].second;
                if(ind>=0)
                {
                    fnd=nz.lower_bound(ind);
                    if(fnd!=nz.end())
                    {
                        if(*fnd==ind)
                        {
                            c[ele]=v[i].first;
                            cnt++;
                            done[ele]=true;
                        }
                    }
                }
            }
        }

    for(i=0;i<n;i++)
    {
        printf("%d\n",c[i]);
    }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#define Maxx 100100
using namespace std;

int a[Maxx],b[Maxx],n,d;
long long x;

long long getNextX(void)
{
     x = (x * 37 + 10007) % 1000000007;
    return x;
}

void calc(void)
{
    long long i;
    for(i=0;i<n;i++)
    {
        a[i]=i+1;
    }
    for(i=0;i<n;i++)
    {
        swap(a[i],a[getNextX()%(i+1)]);
    }
    for(i=0;i<n;i++)
    {
        if(i<d)
        {
            b[i]=1;
        }
        else
        {
            b[i]=0;
        }
    }
    for(i=0;i<n;i++)
    {
        swap(b[i],b[getNextX()%(i+1)]);
    }
}

main()
{
    int i,j,k,ind,ele,cnt=0;
    cin>>n>>d>>x;

    calc();

    int c[n];
    bool done[n],solve=true;
    fill(c,c+n,0);
    fill(done,done+n,false);
    vector<pair<int,int> > v;
    vector<int> non_zero,remain;
    set<int> nz;
    set<int>::iterator fnd;

    for(i=0;i<n;i++)
    {
        v.push_back(make_pair(a[i],i));
    }
    sort(v.rbegin(),v.rend());
    for(i=0;i<n;i++)
    {
        if(b[i])
        {
            non_zero.push_back(i);
            nz.insert(i);
        }
    }

    for(i=0;i<non_zero[0];i++)
    {
        done[i]=true;
        cnt++;
    }

    k=-1;
    for(i=0;i<n&&solve;i++)
        for(j=0;j<non_zero.size()&&solve;j++)
    {
        ind=v[i].second+non_zero[j];
        if(ind>=n)
        {
            j=non_zero.size()-1;
        }
        else if(!done[ind])
        {
            c[ind]=v[i].first;
            cnt++;
            done[ind]=true; //if(ind<50)cout<<ind<<endl;
        }
        if(n-cnt<30)
        {
            k=i;
            solve=false;
        }
    }

    for(i=0;i<n;i++)
    {
        if(!done[i])
        {
            remain.push_back(i);
        }
    }

        for(i=k;i<n&&cnt!=n;i++)
        {
            for(j=0;j<remain.size()&&cnt!=n;j++)
            {
                ele=remain[j];
                if(done[ele]) continue;
                ind=ele-v[i].second;
                if(ind>=0)
                {
                    fnd=nz.lower_bound(ind);
                    if(fnd!=nz.end())
                    {
                        if(*fnd==ind)
                        {
                            c[ele]=v[i].first;
                            cnt++;
                            done[ele]=true;
                        }
                    }
                }
            }
        }

    for(i=0;i<n;i++)
    {
        printf("%d\n",c[i]);
    }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#define Maxx 100100
using namespace std;

int a[Maxx],b[Maxx],n,d;
long long x;

long long getNextX(void)
{
     x = (x * 37 + 10007) % 1000000007;
    return x;
}

void calc(void)
{
    long long i;
    for(i=0;i<n;i++)
    {
        a[i]=i+1;
    }
    for(i=0;i<n;i++)
    {
        swap(a[i],a[getNextX()%(i+1)]);
    }
    for(i=0;i<n;i++)
    {
        if(i<d)
        {
            b[i]=1;
        }
        else
        {
            b[i]=0;
        }
    }
    for(i=0;i<n;i++)
    {
        swap(b[i],b[getNextX()%(i+1)]);
    }
}

main()
{
    int i,j,k,ind,ele,cnt=0;
    cin>>n>>d>>x;

    calc();

    int c[n];
    bool done[n],solve=true;
    fill(c,c+n,0);
    fill(done,done+n,false);
    vector<pair<int,int> > v;
    vector<int> non_zero,remain;
    set<int> nz;
    set<int>::iterator fnd;

    for(i=0;i<n;i++)
    {
        v.push_back(make_pair(a[i],i));
    }
    sort(v.rbegin(),v.rend());
    for(i=0;i<n;i++)
    {
        if(b[i])
        {
            non_zero.push_back(i);
            nz.insert(i);
        }
    }

    for(i=0;i<non_zero[0];i++)
    {
        done[i]=true;
        cnt++;
    }

    k=-1;
    for(i=0;i<n&&solve;i++)
        for(j=0;j<non_zero.size()&&solve;j++)
    {
        ind=v[i].second+non_zero[j];
        if(ind>=n)
        {
            j=non_zero.size()-1;
        }
        else if(!done[ind])
        {
            c[ind]=v[i].first;
            cnt++;
            done[ind]=true; //if(ind<50)cout<<ind<<endl;
        }
        if(n-cnt<50)
        {
            k=i;
            solve=false;
        }
    }

    for(i=0;i<n;i++)
    {
        if(!done[i])
        {
            remain.push_back(i);
        }
    }

        for(i=k;i<n&&cnt!=n;i++)
        {
            for(j=0;j<remain.size()&&cnt!=n;j++)
            {
                ele=remain[j];
                if(done[ele]) continue;
                ind=ele-v[i].second;
                if(ind>=0)
                {
                    fnd=nz.lower_bound(ind);
                    if(fnd!=nz.end())
                    {
                        if(*fnd==ind)
                        {
                            c[ele]=v[i].first;
                            cnt++;
                            done[ele]=true;
                        }
                    }
                }
            }
        }

    for(i=0;i<n;i++)
    {
        printf("%d\n",c[i]);
    }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#define Maxx 100100
using namespace std;

int a[Maxx],b[Maxx],n,d;
long long x;

long long getNextX(void)
{
     x = (x * 37 + 10007) % 1000000007;
    return x;
}

void calc(void)
{
    long long i;
    for(i=0;i<n;i++)
    {
        a[i]=i+1;
    }
    for(i=0;i<n;i++)
    {
        swap(a[i],a[getNextX()%(i+1)]);
    }
    for(i=0;i<n;i++)
    {
        if(i<d)
        {
            b[i]=1;
        }
        else
        {
            b[i]=0;
        }
    }
    for(i=0;i<n;i++)
    {
        swap(b[i],b[getNextX()%(i+1)]);
    }
}

main()
{
    int i,j,k,ind,ele,cnt=0;
    cin>>n>>d>>x;

    calc();

    int c[n];
    bool done[n],solve=true;
    fill(c,c+n,0);
    fill(done,done+n,false);
    vector<pair<int,int> > v;
    vector<int> non_zero,remain;
    set<int> nz;
    set<int>::iterator fnd;

    for(i=0;i<n;i++)
    {
        v.push_back(make_pair(a[i],i));
    }
    sort(v.rbegin(),v.rend());
    for(i=0;i<n;i++)
    {
        if(b[i])
        {
            non_zero.push_back(i);
            nz.insert(i);
        }
    }

    for(i=0;i<non_zero[0];i++)
    {
        done[i]=true;
        cnt++;
    }

    k=-1;
    for(i=0;i<n&&solve;i++)
        for(j=0;j<non_zero.size()&&solve;j++)
    {
        ind=v[i].second+non_zero[j];
        if(ind>=n)
        {
            j=non_zero.size()-1;
        }
        else if(!done[ind])
        {
            c[ind]=v[i].first;
            cnt++;
            done[ind]=true; //if(ind<50)cout<<ind<<endl;
        }
        if(n-cnt<300)
        {
            k=i;
            solve=false;
        }
    }

    for(i=0;i<n;i++)
    {
        if(!done[i])
        {
            remain.push_back(i);
        }
    }

        for(i=k;i<n&&cnt!=n;i++)
        {
            for(j=0;j<remain.size()&&cnt!=n;j++)
            {
                ele=remain[j];
                if(done[ele]) continue;
                ind=ele-v[i].second;
                if(ind>=0)
                {
                    fnd=nz.lower_bound(ind);
                    if(fnd!=nz.end())
                    {
                        if(*fnd==ind)
                        {
                            c[ele]=v[i].first;
                            cnt++;
                            done[ele]=true;
                        }
                    }
                }
            }
        }

    for(i=0;i<n;i++)
    {
        printf("%d\n",c[i]);
    }
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
const int MAXN = 100010;
int n;
int a[MAXN];
int b[MAXN];
int pos[MAXN];
int x;
int d;

int getNextX()
{
    x= ((ll)x * 37+10007) % 1000000007;
    return x;
}

void initAB()
{   int i;
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
}

int is[MAXN];

int main()
{
    while(scanf("%d%d%d",&n,&d,&x)!=EOF)
    {
        initAB();
        memset(pos,-1,sizeof(pos));
        int cn=0;
        int mx=50;
        for(int i=0;i<n;i++){
            pos[a[i]]=i;
            if(b[i])is[cn++]=i;
            int ans=0;
       //     if(cn<mx){
       //         for(int j=0;j<cn;j++)
       //             if(ans<a[i-is[j]]){
      //                  ans=a[i-is[j]];
       //             }
        //    }
        //    else {
                for(int j=n;j>0;j--){
                    if(pos[j]!=-1 && b[i-pos[j]]){
                        ans=j;
                        break;
                    }
                }
        //    }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
const int MAXN = 100010;
int n;
int a[MAXN];
int b[MAXN];
int pos[MAXN];
int x;
int d;

int getNextX()
{
    x= ((ll)x * 37+10007) % 1000000007;
    return x;
}

void initAB()
{   int i;
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
}

int is[MAXN];

int main()
{
    while(scanf("%d%d%d",&n,&d,&x)!=EOF)
    {
        initAB();
        memset(pos,-1,sizeof(pos));
        int cn=0;
        int mx=300;
        for(int i=0;i<n;i++){
            pos[a[i]]=i;
            if(b[i])is[cn++]=i;
            int ans=0;
            if(cn<mx){
                for(int j=0;j<cn;j++)
                    if(ans<a[i-is[j]]){
                        ans=a[i-is[j]];
                    }
            }
            else {
                for(int j=n;j>0;j--){
                    if(pos[j]!=-1 && b[i-pos[j]]){
                        ans=j;
                        break;
                    }
                }
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
const int MAXN = 100010;
int n;
int a[MAXN];
int b[MAXN];
int pos[MAXN];
int x;
int d;

int getNextX()
{
    x= ((ll)x * 37+10007) % 1000000007;
    return x;
}

void initAB()
{   int i;
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
}

int is[MAXN];

int main()
{
    while(scanf("%d%d%d",&n,&d,&x)!=EOF)
    {
        initAB();
        memset(pos,-1,sizeof(pos));
        int cn=0;
        int mx=200;
        for(int i=0;i<n;i++){
            pos[a[i]]=i;
            if(b[i])is[cn++]=i;
            int ans=0;
            if(cn<mx){
                for(int j=0;j<cn;j++)
                    if(ans<a[i-is[j]]){
                        ans=a[i-is[j]];
                    }
            }
            else {
                for(int j=n;j>0;j--){
                    if(pos[j]!=-1 && b[i-pos[j]]){
                        ans=j;
                        break;
                    }
                }
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
const int MAXN = 100010;
int n;
int a[MAXN];
int b[MAXN];
int pos[MAXN];
int x;
int d;

int getNextX()
{
    x= ((ll)x * 37+10007) % 1000000007;
    return x;
}

void initAB()
{   int i;
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
}

int is[MAXN];

int main()
{
    while(scanf("%d%d%d",&n,&d,&x)!=EOF)
    {
        initAB();
        memset(pos,-1,sizeof(pos));
        int cn=0;
        int mx=350;
        for(int i=0;i<n;i++){
            pos[a[i]]=i;
            if(b[i])is[cn++]=i;
            int ans=0;
            if(cn<mx){
                for(int j=0;j<cn;j++)
                    if(ans<a[i-is[j]]){
                        ans=a[i-is[j]];
                    }
            }
            else {
                for(int j=n;j>0;j--){
                    if(pos[j]!=-1 && b[i-pos[j]]){
                        ans=j;
                        break;
                    }
                }
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
const int MAXN = 100010;
int n;
int a[MAXN];
int b[MAXN];
int pos[MAXN];
int x;
int d;

int getNextX()
{
    x= ((ll)x * 37+10007) % 1000000007;
    return x;
}

void initAB()
{   int i;
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
}

int is[MAXN];

int main()
{
    while(scanf("%d%d%d",&n,&d,&x)!=EOF)
    {
        initAB();
        memset(pos,-1,sizeof(pos));
        int cn=0;
        int mx=50;
        for(int i=0;i<n;i++){
            pos[a[i]]=i;
            if(b[i])is[cn++]=i;
            int ans=0;
            if(cn<mx){
                for(int j=0;j<cn;j++)
                    if(ans<a[i-is[j]]){
                        ans=a[i-is[j]];
                    }
            }
            else {
                for(int j=n;j>0;j--){
                    if(pos[j]!=-1 && b[i-pos[j]]){
                        ans=j;
                        break;
                    }
                }
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
const int MAXN = 100010;
int n;
int a[MAXN];
int b[MAXN];
int pos[MAXN];
int x;
int d;

int getNextX()
{
    x= ((ll)x * 37+10007) % 1000000007;
    return x;
}

void initAB()
{   int i;
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
}

int is[MAXN];

int main()
{
    while(scanf("%d%d%d",&n,&d,&x)!=EOF)
    {
        initAB();
        memset(pos,-1,sizeof(pos));
        int cn=0;
        int mx=320;
        for(int i=0;i<n;i++){
            pos[a[i]]=i;
            if(b[i])is[cn++]=i;
            int ans=0;
            if(cn<mx){
                for(int j=0;j<cn;j++)
                    if(ans<a[i-is[j]]){
                        ans=a[i-is[j]];
                    }
            }
            else {
                for(int j=n;j>0;j--){
                    if(pos[j]!=-1 && b[i-pos[j]]){
                        ans=j;
                        break;
                    }
                }
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
const int MAXN = 100010;
int n;
int a[MAXN];
int b[MAXN];
int pos[MAXN];
int x;
int d;

int getNextX()
{
    x= ((ll)x * 37+10007) % 1000000007;
    return x;
}

void initAB()
{   int i;
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
}

int is[MAXN];

int main()
{
    while(scanf("%d%d%d",&n,&d,&x)!=EOF)
    {
        initAB();
        memset(pos,-1,sizeof(pos));
        int cn=0;
        int mx=280;
        for(int i=0;i<n;i++){
            pos[a[i]]=i;
            if(b[i])is[cn++]=i;
            int ans=0;
            if(cn<mx){
                for(int j=0;j<cn;j++)
                    if(ans<a[i-is[j]]){
                        ans=a[i-is[j]];
                    }
            }
            else {
                for(int j=n;j>0;j--){
                    if(pos[j]!=-1 && b[i-pos[j]]){
                        ans=j;
                        break;
                    }
                }
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
const int MAXN = 100010;
int n;
int a[MAXN];
int b[MAXN];
int pos[MAXN];
int x;
int d;

int getNextX()
{
    x= ((ll)x * 37+10007) % 1000000007;
    return x;
}

void initAB()
{   int i;
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
}

int is[MAXN];

int main()
{
    while(scanf("%d%d%d",&n,&d,&x)!=EOF)
    {
        initAB();
        memset(pos,-1,sizeof(pos));
        int cn=0;
        int mx=100;
        for(int i=0;i<n;i++){
            pos[a[i]]=i;
            if(b[i])is[cn++]=i;
            int ans=0;
            if(cn<mx){
                for(int j=0;j<cn;j++)
                    if(ans<a[i-is[j]]){
                        ans=a[i-is[j]];
                    }
            }
            else {
                for(int j=n;j>0;j--){
                    if(pos[j]!=-1 && b[i-pos[j]]){
                        ans=j;
                        break;
                    }
                }
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
const int MAXN = 100010;
int n;
int a[MAXN];
int b[MAXN];
int pos[MAXN];
int x;
int d;

int getNextX()
{
    x= ((ll)x * 37+10007) % 1000000007;
    return x;
}

void initAB()
{   int i;
    for(i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
}

int is[MAXN];

int main()
{
    while(scanf("%d%d%d",&n,&d,&x)!=EOF)
    {
        initAB();
        memset(pos,-1,sizeof(pos));
        int cn=0;
        int mx=10;
        for(int i=0;i<n;i++){
            pos[a[i]]=i;
            if(b[i])is[cn++]=i;
            int ans=0;
            if(cn<mx){
                for(int j=0;j<cn;j++)
                    if(ans<a[i-is[j]]){
                        ans=a[i-is[j]];
                    }
            }
            else {
                for(int j=n;j>0;j--){
                    if(pos[j]!=-1 && b[i-pos[j]]){
                        ans=j;
                        break;
                    }
                }
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include<bits/stdc++.h>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef long long ll;
typedef pair<ll,int> li;
ll a[100010],b[10010],n,d,x;
vector<li> vec;
vector<int> arr;

inline ll getNextX(){ return x = ( x * 37LL + 10007LL ) % 1000000007LL; }
void initAB(){
  rep(i,n) a[i] = i + 1;
  rep(i,n) swap(a[i],a[getNextX()%(ll)(i+1)]);
  rep(i,n) b[i] = ((i<d)?1:0);
  rep(i,n) swap(b[i],b[getNextX()%(ll)(i+1)]);
}

void dwell_on(){
  rep(i,n) {
    ll maxi = 0;
    rep(j,(int)arr.size()) if( i-arr[j] >= 0 ) maxi = max(maxi,a[i-arr[j]]);
    cout << maxi << endl;
  }
}

void compute(){
  rep(i,n) vec.push_back(li(a[i],i));
  sort(vec.begin(),vec.end(),greater<li>());
  rep(i,n){
    ll maxi = 0;
    rep(j,n) if( vec[i].second <= i && i-vec[j].second >= 0 && b[i-vec[j].second] ) { maxi = vec[i].first; break; }
    cout << maxi << endl;
  }
}

int main(){
  cin >> n >> d >> x;
  initAB();
  rep(i,n) if( b[i] ) arr.push_back(i);
  if( d <= 1000 ) dwell_on();
  else compute();

  return 0;
}


#include<bits/stdc++.h>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef long long ll;
typedef pair<ll,int> li;
ll a[100010],b[100010],n,d,x;
vector<li> vec;
vector<int> arr;

inline ll getNextX(){ return x = ( x * 37LL + 10007LL ) % 1000000007LL; }
void initAB(){
  rep(i,n) a[i] = i + 1;
  rep(i,n) swap(a[i],a[getNextX()%(ll)(i+1)]);
  rep(i,n) b[i] = ((i<d)?1:0);
  rep(i,n) swap(b[i],b[getNextX()%(ll)(i+1)]);
}

void dwell_on(){
  rep(i,n) if( b[i] ) arr.push_back(i);
  rep(i,n) {
    ll maxi = 0;
    rep(j,(int)arr.size()) if( i-arr[j] >= 0 ) maxi = max(maxi,a[i-arr[j]]);
    cout << maxi << endl;
  }
}

void compute(){
  rep(i,n) vec.push_back(li(a[i],i));
  sort(vec.begin(),vec.end(),greater<li>());
  rep(i,n){
    ll maxi = 0;
    rep(j,n) if( vec[j].second <= i && i-vec[j].second >= 0 && b[i-vec[j].second] ) { maxi = vec[j].first; break; }
    cout << maxi << endl;
  }
}

int main(){
  cin >> n >> d >> x;
  initAB();
  if( d <= 1000 ) dwell_on();
  else compute();
  return 0;
}


#include<bits/stdc++.h>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef long long ll;
typedef pair<ll,int> li;
ll a[100010],b[10010],n,d,x;
vector<li> vec;
vector<int> arr;

inline ll getNextX(){ return x = ( x * 37LL + 10007LL ) % 1000000007LL; }
void initAB(){
  rep(i,n) a[i] = i + 1;
  rep(i,n) swap(a[i],a[getNextX()%(ll)(i+1)]);
  rep(i,n) b[i] = ((i<d)?1:0);
  rep(i,n) swap(b[i],b[getNextX()%(ll)(i+1)]);
}

void dwell_on(){
  rep(i,n) {
    ll maxi = 0;
    rep(j,(int)arr.size()) if( i-arr[j] >= 0 ) maxi = max(maxi,a[i-arr[j]]);
    cout << maxi << endl;
  }
}

void compute(){
  rep(i,n) vec.push_back(li(a[i],i));
  sort(vec.begin(),vec.end(),greater<li>());
  rep(i,n){
    ll maxi = 0;
    rep(j,n) if( vec[j].second <= i && i-vec[j].second >= 0 && b[i-vec[j].second] ) { maxi = vec[j].first; break; }
    cout << maxi << endl;
  }
}

int main(){
  cin >> n >> d >> x;
  initAB();
  rep(i,n) if( b[i] ) arr.push_back(i);
  if( d <= 1000 ) dwell_on();
  else compute();

  return 0;
}


#include <stdio.h>
#include <iostream>
#include <memory.h>
#include <map>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
ll x;
int n,d;
int a[100001],b[100001],seg[400001];
ll getNextX() {
    x = (x * 37 + 10007) % 1000000007;
    return x;
}
void initAB() {
    for(int i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(int i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(int i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(int i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
}
void build(int n,int s,int e){
	if(s>e)
		return;
	if(s==e){
		seg[n]=a[s];
		return;
	}
	build(n*2,s,(s+e)/2);
	build(n*2+1,(s+e)/2+1,e);
	seg[n]=max(seg[n*2],seg[n*2+1]);
}
int X,y;
int get(int n,int s,int e){
	if(s>e || X>e || y<s)
		return 0;
	if(s>=X && e<=y)
		return seg[n];
	return max(get(n*2,s,(s+e)/2),get(n*2+1,(s+e)/2+1,e));
}
int main()
{
	cin>>n>>d>>x;
	initAB();
	build(1,0,n-1);
	for(int i=0;i<n;++i)
	printf("%d ",a[i]);
	puts("");
	int o;
	for(int i=0;i<n;++i){
		if(i<d){
			X=0;
			y=i;
			printf("%d\n",get(1,0,n-1));
			continue;
		}
		o=0;
		if((i+1)%2==1 && b[(i+1)/2])
			o=a[(i+1)/2];
		int md=(i+1)/2;
		int len=min(d,md);
		X=i-len+1;
		y=i;
		o=max(o,get(1,0,n-1));
		len=d-md;
		if(0 && len>0){
			X=md-len;
			y=md-1;
			o=max(o,get(1,0,n-1));
		}
		printf("%d\n",o);
	}
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <memory.h>
#include <map>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
ll x;
int n,d;
int a[100001],b[100001],seg[400001];
ll getNextX() {
    x = (x * 37 + 10007) % 1000000007;
    return x;
}
void initAB() {
    for(int i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(int i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(int i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(int i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
}
void build(int n,int s,int e){
	if(s>e)
		return;
	if(s==e){
		seg[n]=a[s];
		return;
	}
	build(n*2,s,(s+e)/2);
	build(n*2+1,(s+e)/2+1,e);
	seg[n]=max(seg[n*2],seg[n*2+1]);
}
int X,y;
int get(int n,int s,int e){
	if(s>e || X>e || y<s)
		return 0;
	if(s>=X && e<=y)
		return seg[n];
	return max(get(n*2,s,(s+e)/2),get(n*2+1,(s+e)/2+1,e));
}
int main()
{
	cin>>n>>d>>x;
	initAB();
	build(1,0,n-1);
	int o;
	for(int i=0;i<n;++i){
		if(i<d){
			X=0;
			y=i;
			printf("%d\n",get(1,0,n-1));
			continue;
		}
		o=0;
		if((i+1)%2==1 && b[(i+1)/2])
			o=a[(i+1)/2];
		int md=(i+1)/2;
		int len=min(d,md);
		X=i-len+1;
		y=i;
		o=max(o,get(1,0,n-1));
		len=d-md;
		if((i+1)%2==1)
			--len;
		if(len>0){
			X=md-len;
			y=md-1;
			o=max(o,get(1,0,n-1));
		}
		printf("%d\n",o);
	}
	return 0;
}


//#pragma comment(linker,"/STACK:100000000000,100000000000")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <list>
#include <sstream>
#include <ctime>
#include <climits>
#include <bitset>
#include <list>
#include <cassert>
#include <complex>

using namespace std;

/* Constants begin */
const long long inf = 2e18 + 7;
const long long mod = 1e9 + 7;
const double eps = 1e-12;
const double PI = 2*acos(0.0);
const double E = 2.71828;
/* Constants end */

/* Defines begin */
#define pb push_back
#define mp make_pair
#define ll long long
#define double long double
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define forn(i,n) for (int (i)=0; (i)<(n); ++(i))
#define random (rand()<<16|rand())
#define sqr(x) (x)*(x)
#define base complex<double>
/* Defines end */

int n, d, X;

int nxt(){
  X = (1LL * X * 37 + 10007) % 1000000007;
  return X;
}

int a[100005], b[100005];
int pos[100005];
int res[100005];
set<int> x, y;

int main(void){
  #ifdef nobik
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
  #endif
  scanf("%d %d %d", &n, &d, &X);
  forn(i, n){
    a[i] = i + 1;
  }
  forn(i, n){
    swap(a[i], a[nxt() % (i + 1)]);
  }
  forn(i, n){
    if(i < d) b[i] = 1; else b[i] = 0;
  }
  forn(i, n){
    swap(b[i], b[nxt() % (i + 1)]);
  }
  forn(i, n) x.insert(i);
  forn(i, n) if(b[i]) y.insert(i);
  forn(i, n){
    pos[a[i]] = i;
  }
  for(int i = n; i >= 1; --i){
    int it = pos[i];
    set<int> :: iterator F = x.lower_bound(it);
    set<int> :: iterator S = y.begin();
    for(; F != x.end();){
      int cur = *F;
      S = y.lower_bound(cur - it);
      if(S == y.end()){
        break;
      }
      if(*S == cur - it){
        res[cur] = i;
        x.erase(F);
      }
      F = x.lower_bound(it + *S);
    }
  }
  forn(i, n) printf("%d\n", res[i]);
  return 0;
}


#include <stdio.h>
#include <iostream>
#include <memory.h>
#include <map>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
ll x;
int n,d;
int a[100001],b[100001],seg[400001];
ll getNextX() {
    x = (x * 37 + 10007) % 1000000007;
    return x;
}
void initAB() {
    for(int i = 0; i < n; i = i + 1){
        a[i] = i + 1;
    }
    for(int i = 0; i < n; i = i + 1){
        swap(a[i], a[getNextX() % (i + 1)]);
    }
    for(int i = 0; i < n; i = i + 1){
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }
    for(int i = 0; i < n; i = i + 1){
        swap(b[i], b[getNextX() % (i + 1)]);
    }
}
void build(int n,int s,int e){
	if(s>e)
		return;
	if(s==e){
		seg[n]=a[s];
		return;
	}
	build(n*2,s,(s+e)/2);
	build(n*2+1,(s+e)/2+1,e);
	seg[n]=max(seg[n*2],seg[n*2+1]);
}
int X,y;
int get(int n,int s,int e){
	if(s>e || X>e || y<s)
		return 0;
	if(s>=X && e<=y)
		return seg[n];
	return max(get(n*2,s,(s+e)/2),get(n*2+1,(s+e)/2+1,e));
}
int main()
{
	cin>>n>>d>>x;
	initAB();
	build(1,0,n-1);
	int o;
	for(int i=0;i<n;++i)
	printf("%d ",a[i]);
	puts("");
	for(int i=0;i<n;++i)
	printf("%d ",b[i]);
	puts("");
	for(int i=0;i<n;++i){
		if(i<d){
			X=0;
			y=i;
			printf("%d\n",get(1,0,n-1));
			continue;
		}
		o=0;
		if((i+1)%2==1 && b[(i+1)/2])
			o=a[(i+1)/2];
		int md=(i+1)/2;
		int len=min(d,md);
		X=i-len+1;
		y=i;
		o=max(o,get(1,0,n-1));
		len=d-md;
		if((i+1)%2==1)
			--len;
		if(len>0){
			X=md-len;
			y=md-1;
			o=max(o,get(1,0,n-1));
		}
		printf("%d\n",o);
	}
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#define ll long long
using namespace std;

const int MAXN = 100005;

int a[MAXN],b[MAXN],c[MAXN];
int tb[MAXN];
int d,n;
ll x;

ll getNextX()
{
    x = (x * 37 + 10007) % 1000000007;
    return x;
}

void initAB()
{
    for(int i = 0; i < n; i = i + 1)
    {
        a[i] = i + 1;
    }

    for(int i = 0; i < n; i = i + 1)
    {
        swap(a[i], a[getNextX() % (i + 1)]);
    }

    for(int i = 0; i < n; i = i + 1)
    {
        if (i < d)
            b[i] = 1;
        else
            b[i] = 0;
    }

    for(int i = 0; i < n; i = i + 1)
    {
        swap(b[i], b[getNextX() % (i + 1)]);
    }
}

struct node
{
    int p,num;
    bool operator < (const node &t) const
    {
        return num>t.num;
    }
};

node nd[MAXN];

int main()
{
#ifdef PKWV
    freopen("in.in", "r", stdin);
#endif // PKWV
    while(cin>>n>>d>>x)
    {
        initAB();
        int cnt=0;
        for(int i=0;i<n;i++)
        {
            nd[i].num=a[i];
            nd[i].p=i;
        }
        sort(nd,nd+n);
        int l=0;
        for(int i=0;i<n;i++)
        {
            if(b[i]==1)
            {
                tb[l++]=i;
            }
        }
        memset(c,-1,sizeof(c));
        for(int i=0;i<n;i++)
        {
            int p=nd[i].p;
            for(int j=0;j<l;j++)
            {
                if(p+tb[j]<n&&c[p+tb[j]]==-1)
                {
                    c[p+tb[j]]=a[p];
                    cnt++;
                    if(cnt==n) break;
                }
            }
            if(cnt==n) break;
        }
        for(int i=0;i<n;i++)
        {
            printf("%d\n",c[i]==-1?0:c[i]);
        }
    }
    return 0;
}


#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<map>
#include<cstring>
#include<string>
using namespace std;

typedef long long LL;

#define rep(i,n) for(int i=0;i<n;++i)
typedef double db;
#define mp make_pair
#define pb push_back

const int MAXN = 1111;
int n, m;
db p[ MAXN ][ MAXN ];
int a[ MAXN ];

int main(){
	while( cin >> n >> m) {
		for(int i=1;i<=n;++i) scanf("%d",a + i);
		memset( p, 0, sizeof p);
		for(int i=1;i<=n;++i) for(int j=1;j<=n;++j)
			if( a[i] > a[j] ) p[ i ][ j ] = 1;

		for(int c=0;c<m;++c) {
			int x, y; scanf("%d%d", &x, &y);
			p[ x ][ y ] = p[ y ][ x ] = 1.0 / 2;
			for(int i = 1; i <= n; ++ i) if(i!=x && i!=y) {
				db pxi = p[x][i], pyi = p[y][i], pix = p[i][x] , piy = p[i][y];
				p[x][i] = 0.5 * pxi + 0.5 * pyi,
				p[i][x] = 0.5 * pix + 0.5 * piy,
				p[y][i] = 0.5 * pyi + 0.5 * pxi;
				p[i][y] = 0.5 * piy + 0.5 * pix;
			}
		}
		db ans = .0;
		for(int i=2;i<=n;++i) for(int j=1;j<i;++j) ans += p[ j ][ i ];
		printf("%.10f\n", ans);
	}
	return 0;
}


#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<map>
#include<cstring>
#include<string>
using namespace std;

typedef long long LL;

#define rep(i,n) for(int i=0;i<n;++i)
typedef double db;
#define mp make_pair
#define pb push_back

const int MAXN = 1111;
int n, m;
db p[ MAXN ][ MAXN ];
int a[ MAXN ];

int main(){
	while( cin >> n >> m) {
		for(int i=1;i<=n;++i) scanf("%d",a + i);
		memset( p, 0, sizeof p);
		for(int i=1;i<=n;++i) for(int j=1;j<=n;++j)
			if( a[i] > a[j] ) p[ i ][ j ] = 1;
		for(int c=0;c<m;++c) {
			int x, y; scanf("%d%d", &x, &y);
			p[ x ][ y ] = p[ y ][ x ] = 1.0 / 2;
			for(int i = 1; i <= n; ++ i) if(i!=x && i!=y) {
				db pxi = p[x][i], pyi = p[y][i], pix = p[i][x] , piy = p[i][y];
				p[x][i] = 0.5 * pxi + 0.5 * pyi,
				p[i][x] = 0.5 * pix + 0.5 * piy,
				p[y][i] = 0.5 * pyi + 0.5 * pxi;
				p[i][y] = 0.5 * piy + 0.5 * pix;
			}
		}
		db ans = .0;
		for(int i=2;i<=n;++i) for(int j=1;j<i;++j) ans += p[ i ][ j ];
		printf("%.10f\n", ans);
	}
	return 0;
}


#include <cstdio>
#include <cstring>

int n, m;
int a[1024];
double prs[1024][1024];

int main() {
    memset(prs, 0, sizeof(prs));
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (a[i] < a[j]) {
                prs[i][j] = 1.0;
            } else {
                prs[i][j] = 0.0;
            }
        }
    }
    for (int i = 0; i < m; ++i) {
        int l, r;
        scanf("%d %d", &l, &r);
        --l; --r;
        for (int j = 0; j < n; ++j) {
            if (j == l || j == r) {
                continue;
            }
            double jsm = 0.5 * (prs[j][l] + prs[j][r]);
            prs[j][l] = prs[j][r] = jsm;
            prs[l][j] = prs[r][j] = 1.0 - jsm;
        }
        prs[l][r] = prs[r][l] = 0.5;
    }
    double ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < i; ++j) {
            ans += prs[i][j];
        }
    }
    printf("%.10lf\n", ans);
    return 0;
}


#include<stdio.h>

const int MAXN=1000+9;

int p[MAXN];
double r[MAXN][MAXN];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int n,m,i,j,a,b;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;++i)
		scanf("%d",p+i);
	for(i=1;i<=n;++i)
		for(j=1;j<=n;++j)
			if(p[i]<p[j])
				r[i][j]=1;
	for(i=0;i<m;++i)
	{
		scanf("%d%d",&a,&b);
		if(a>b)
			j=a,a=b,b=j;
		r[a][b]=r[b][a]=(r[a][b]+r[b][a])/2;
		for(j=a+1;j<b;++j)
		{
			r[a][j]=r[j][a]=(r[a][j]+r[j][a])/2;
			r[b][j]=r[j][b]=(r[b][j]+r[j][b])/2;
		}
	}
	double ans=0;
	for(i=2;i<=n;++i)
		for(j=1;j<i;++j)
			ans+=r[i][j];
	printf("%lf\n",ans);
	return 0;
}


#include<stdio.h>

const int MAXN=1000+9;

int p[MAXN];
double r[MAXN][MAXN];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int n,m,i,j,a,b;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;++i)
		scanf("%d",p+i);
	for(i=1;i<=n;++i)
		for(j=1;j<=n;++j)
			if(p[i]<p[j])
				r[i][j]=1;
	for(i=0;i<m;++i)
	{
		scanf("%d%d",&a,&b);
		if(a>b)
			j=a,a=b,b=j;
		r[a][b]=r[b][a]=.5;
		for(j=1;j<=n;++j)
			if(i!=a && i!=b)
			{
				r[a][j]=r[j][a]=(r[a][j]+r[j][a])/2;
				r[b][j]=r[j][b]=(r[b][j]+r[j][b])/2;
			}
	}
	double ans=0;
	for(i=2;i<=n;++i)
		for(j=1;j<i;++j)
			ans+=r[i][j];
	printf("%lf\n",ans);
	return 0;
}


#include<stdio.h>

const int MAXN=1000+9;

int p[MAXN];
double r[MAXN][MAXN];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int n,m,i,j,a,b;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;++i)
		scanf("%d",p+i);
	for(i=1;i<=n;++i)
		for(j=1;j<=n;++j)
			if(p[i]<p[j])
				r[i][j]=1;
	for(i=0;i<m;++i)
	{
		scanf("%d%d",&a,&b);
		if(a>b)
			j=a,a=b,b=j;
		r[a][b]=r[b][a]=.5;
		for(j=1;j<=n;++j)
			if(j!=a && j!=b)
			{
				r[a][j]=r[b][j]=(r[a][j]+r[b][j])/2;
				r[j][a]=r[j][b]=(r[j][a]+r[j][b])/2;
			}
	}
	double ans=0;
	for(i=2;i<=n;++i)
		for(j=1;j<i;++j)
			ans+=r[i][j];
	printf("%lf\n",ans);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define orta (bas + son >> 1)
#define sag (k + k + 1)
#define sol (k + k)
#define endl '\n'
#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)
#define mp make_pair
#define nd second
#define st first
#define type(x) __typeof(x.begin())

typedef pair < int ,int > pii;

typedef long long ll;

const long long linf = 1e18+5;
const int mod = (int) 1e9 + 7;
const int logN = 17;
const int inf = 1e9;
const int N = 1e3 + 5;

vector< double > dp[N][N];
int n, m, a[N], x, y, t;
vector< int > v[N][N];
pii e[N];

double f(int x, int y, int w) {
	if(w == v[x][y].size()) return x < y;
	double &r = dp[x][y][w];
	if(r >= 0) return r;
	int ind = v[x][y][w];
	r = f(x, y, w + 1) * 0.5;
	if(e[ind].nd == x) x = e[ind].st;
	else if(e[ind].st == x) x = e[ind].nd;
	if(e[ind].nd == y) y = e[ind].st;
	else if(e[ind].st == y) y = e[ind].nd;
	int last = lower_bound(v[x][y].begin(), v[x][y].end(), ind + 1) - v[x][y].begin();
	return r += f(x, y, last) * 0.5;
}

int main() {

	scanf("%d %d", &n, &m);

	FOR(i, 1, n) {
		scanf("%d", &a[i]);
	}

	FOR(i, 1, m) {
		scanf("%d %d", &x, &y);
		e[i] = mp(x, y);
		FOR(j, 1, n) { v[x][j].pb(i); v[j][x].pb(i); }
		FOR(j, 1, n) { v[y][j].pb(i); v[j][y].pb(i); }
	}

	FOR(i, 1, n)
		FOR(j, 1, n) {
			v[i][j].resize(unique(v[i][j].begin(), v[i][j].end()) - v[i][j].begin());
			dp[i][j].resize(v[i][j].size() + 1, -1);
		}

	FOR(i, 1, n)
		FOR(j, 1, n) {
			if(i == j) continue;

		}

	double ans = 0;

	FOR(i, 1, n)
		FOR(j, i + 1, n) {
			if(a[i] < a[j]) ans += f(j, i, 0);
			else ans += 1 - f(j, i, 0);
		}

	printf("%.12lf\n", ans);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define orta (bas + son >> 1)
#define sag (k + k + 1)
#define sol (k + k)
#define endl '\n'
#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)
#define mp make_pair
#define nd second
#define st first
#define type(x) __typeof(x.begin())

typedef pair < int ,int > pii;

typedef long long ll;

const long long linf = 1e18+5;
const int mod = (int) 1e9 + 7;
const int logN = 17;
const int inf = 1e9;
const int N = 1e3 + 5;

vector< double > dp[N][N];
int n, m, a[N], x, y, t;
vector< int > v[N][N];
pii e[N];

double f(int x, int y, int w) {
	if(w == v[x][y].size()) return x < y;
	if(x > y) return 1.0 - f(y, x, w);
	double &r = dp[x][y][w];
	if(r >= 0) return r;
	int ind = v[x][y][w];
	r = f(x, y, w + 1) * 0.5;
	if(e[ind].nd == x) x = e[ind].st;
	else if(e[ind].st == x) x = e[ind].nd;
	if(e[ind].nd == y) y = e[ind].st;
	else if(e[ind].st == y) y = e[ind].nd;
	int last = lower_bound(v[x][y].begin(), v[x][y].end(), ind + 1) - v[x][y].begin();
	return r += f(x, y, last) * 0.5;
}

int main() {

	scanf("%d %d", &n, &m);

	FOR(i, 1, n) {
		scanf("%d", &a[i]);
	}

	FOR(i, 1, m) {
		scanf("%d %d", &x, &y);
		e[i] = mp(x, y);
		FOR(j, 1, n) { v[x][j].pb(i); v[j][x].pb(i); }
		FOR(j, 1, n) { v[y][j].pb(i); v[j][y].pb(i); }
	}

	FOR(i, 1, n)
		FOR(j, 1, n) {
			v[i][j].resize(unique(v[i][j].begin(), v[i][j].end()) - v[i][j].begin());
			dp[i][j].resize(v[i][j].size() + 1, -1);
		}

	FOR(i, 1, n)
		FOR(j, 1, n) {
			if(i == j) continue;

		}

	double ans = 0;

	FOR(i, 1, n)
		FOR(j, i + 1, n) {
			if(a[i] < a[j]) ans += f(j, i, 0);
			else ans += 1 - f(j, i, 0);
		}

	printf("%.12lf\n", ans);

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cassert>
#include<sstream>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<ctime>
#ifdef __int64
#define lld "%I64d"
#else
#define lld "%lld"
#endif
#define sqr(i) ((i)*(i))
#define fr(i,n) for (int i=0; i<n; i++)
#define fn(i,n) for (int i=n-1; i>=0; i--)
#define fe(i,n) for (__typeof(n.begin()) i=n.begin(); i!=n.end(); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef set<int> si;
typedef set<ll> sl;
typedef set<string> ss;
typedef map<string,int> msi;
typedef map<int,string> mis;
typedef map<int,int> mii;
typedef map<ll,int> mli;
typedef map<int,ll> mil;
typedef pair<int,int> pii;
typedef pair<string,int> psi;
typedef pair<int,string> pis;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
const double pi=acos(-1.0);
const double eps=1e-10;
#define N 1010
int n,m,a[N],x[N],y[N];
double p[N][N];
int main()
{
    scanf("%d%d",&n,&m);
    fr(i,n) scanf("%d",a+i);
    fr(i,m)
    {
        scanf("%d%d",x+i,y+i);
        x[i]--, y[i]--;
        if (x[i]>y[i]) swap(x[i],y[i]);
    }
    fr(i,n) fr(j,n) p[i][j]=a[i]<a[j];
    double ans=0;
    fr(i,n) fr(j,i) if (a[j]>a[i]) ans++;
    fr(i,m)
    {
        for (int j=x[i]+1; j<y[i]; j++)
            ans+=p[x[i]][j]+p[j][y[i]]-1;
        ans+=p[x[i]][y[i]]-0.5;
        fr(j,n)
        {
            if (j==x[i]||j==y[i]) continue;
            p[x[i]][j]=p[y[i]][j]=(p[x[i]][j]+p[y[i]][j])/2.0;
            p[j][x[i]]=p[j][y[i]]=(p[j][x[i]]+p[j][y[i]])/2.0;
        }
        p[x[i]][y[i]]=p[y[i]][x[i]]=0.5;
    }
    printf("%.10lf\n",ans);
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cassert>
#include<sstream>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<ctime>
#ifdef __int64
#define lld "%I64d"
#else
#define lld "%lld"
#endif
#define sqr(i) ((i)*(i))
#define fr(i,n) for (int i=0; i<n; i++)
#define fn(i,n) for (int i=n-1; i>=0; i--)
#define fe(i,n) for (__typeof(n.begin()) i=n.begin(); i!=n.end(); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef set<int> si;
typedef set<ll> sl;
typedef set<string> ss;
typedef map<string,int> msi;
typedef map<int,string> mis;
typedef map<int,int> mii;
typedef map<ll,int> mli;
typedef map<int,ll> mil;
typedef pair<int,int> pii;
typedef pair<string,int> psi;
typedef pair<int,string> pis;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
const double pi=acos(-1.0);
const double eps=1e-10;
#define N 1010
int n,m,a[N];
double f[N][N],g[N][N],x[N][N],tmp[N];
//f is the propotion
//g is the sum
//x is the sum of row i except col j
int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1; i<=n; i++) scanf("%d",a+i);
    for (int i=1; i<=n; i++) f[a[i]][i]=1;
    fr(i,m)
    {
        int p,q;
        scanf("%d%d",&p,&q);
        for (int j=1; j<=n; j++)
            f[j][p]=f[j][q]=(f[j][p]+f[j][q])/2.0;
    }
    for (int i=1; i<=n; i++)
        for (int j=1; j<=n; j++)
            g[i][j]=g[i][j-1]+f[i][j];
    for (int i=1; i<=n; i++)
        for (int j=1; j<=n; j++)
            x[i][j]=g[i][n]-f[i][j];
    double ans=0;
    for (int i=2; i<=n; i++)
    {
        for (int j=1; j<=n; j++)
        {
            if (x[i-1][j]) tmp[j]+=(g[i-1][n]-g[i-1][j])/x[i-1][j];
            ans+=f[i][j]*tmp[j];
        }
    }
    printf("%.10lf\n",ans);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cassert>
#include<sstream>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<ctime>
#ifdef __int64
#define lld "%I64d"
#else
#define lld "%lld"
#endif
#define sqr(i) ((i)*(i))
#define fr(i,n) for (int i=0; i<n; i++)
#define fn(i,n) for (int i=n-1; i>=0; i--)
#define fe(i,n) for (__typeof(n.begin()) i=n.begin(); i!=n.end(); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef set<int> si;
typedef set<ll> sl;
typedef set<string> ss;
typedef map<string,int> msi;
typedef map<int,string> mis;
typedef map<int,int> mii;
typedef map<ll,int> mli;
typedef map<int,ll> mil;
typedef pair<int,int> pii;
typedef pair<string,int> psi;
typedef pair<int,string> pis;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
const double pi=acos(-1.0);
const double eps=1e-10;
#define N 1010
int n,m,a[N];
double f[N][N],g[N][N],x[N][N],tmp[N];
//f is the propotion
//g is the sum
//x is the sum of row i except col j
int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1; i<=n; i++) scanf("%d",a+i);
    for (int i=1; i<=n; i++) f[a[i]][i]=1;
    fr(i,m)
    {
        int p,q;
        scanf("%d%d",&p,&q);
        for (int j=1; j<=n; j++)
            f[j][p]=f[j][q]=(f[j][p]+f[j][q])/2.0;
    }
    for (int i=1; i<=n; i++)
        for (int j=1; j<=n; j++)
            g[i][j]=g[i][j-1]+f[i][j];
    for (int i=1; i<=n; i++)
        for (int j=1; j<=n; j++)
            x[i][j]=g[i][n]-f[i][j];
    double ans=0;
    for (int i=2; i<=n; i++)
    {
        for (int j=1; j<=n; j++)
        {
            if (x[i-1][j]>eps) tmp[j]+=(g[i-1][n]-g[i-1][j])/x[i-1][j];
            ans+=f[i][j]*tmp[j];
        }
    }
    printf("%.10lf\n",ans);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cstdlib>
// #include <cmath>
#include <string>
#define f(x, y, z) for(LL x = (y); x <= (z); ++x)
#define g(x, y, z) for(LL x = (y); x < (z); ++x)
#define h(x, y, z) for(LL x = (y); x >= (z); --x)
#define foreach(x, y) for(__typeof(y.begin()) x = y.begin(); x != y.end(); ++x)
#define rforeach(x, y) for(__typeof(y.rbegin()) x = y.rbegin(); x != y.rend(); ++x)

typedef long long LL;
typedef std::pair<int, int> PII;
typedef long double real;
typedef std::vector<int> VI;

inline void read(int &x){scanf("%d", &x);}
inline void read(LL &x){scanf("%I64d", &x);}
inline void read(double &x){scanf("%lf", &x);}
inline void read(long double &x){
	double tmp; read(tmp); x = tmp;
}
template <class T>
inline void read(T *a, int n){
	g(i, 0, n) read(a[i]);
}

inline void write(int x){printf("%d", x);}
inline void write(LL x){printf("%I64d", x);}
inline void write(double x){printf("%.10lf", x);}
inline void write(long double x){printf("%.10lf", (double) x);}
template <class T>
inline void writeln(T x){write(x); putchar('\n');}
template <class T>
inline void writeln(T *a, int n){
	g(i, 0, n) write(a[i]); putchar('\n');
}
template <class T>
inline void writelnln(T *a, int n){
	g(i, 0, n) writeln(a[i]);
}

int n, m;
int a[1086];
double dp[1086][1086];

int main(){
	read(n); read(m); read(a + 1, n);
	f(i, 1, n) f(j, 1, n) dp[i][j] = (a[i] > a[j]);
	while(m--){
		int a, b; scanf("%d%d", &a, &b);
		f(i, 1, n) if(i != a && i != b){
			dp[i][a] = dp[i][b] = (dp[i][a] + dp[i][b]) / 2;
			dp[a][i] = dp[b][i] = (dp[a][i] + dp[b][i]) / 2;
		}
		dp[a][b] = dp[b][a] = 0.5;
	}
	double ans = 0;
	f(i, 1, n) f(j, 1, n) ans += dp[i][j];
	printf("%.10lf\n", ans / 2);
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cstdlib>
// #include <cmath>
#include <string>
#define f(x, y, z) for(LL x = (y); x <= (z); ++x)
#define g(x, y, z) for(LL x = (y); x < (z); ++x)
#define h(x, y, z) for(LL x = (y); x >= (z); --x)
#define foreach(x, y) for(__typeof(y.begin()) x = y.begin(); x != y.end(); ++x)
#define rforeach(x, y) for(__typeof(y.rbegin()) x = y.rbegin(); x != y.rend(); ++x)

typedef long long LL;
typedef std::pair<int, int> PII;
typedef long double real;
typedef std::vector<int> VI;

inline void read(int &x){scanf("%d", &x);}
inline void read(LL &x){scanf("%I64d", &x);}
inline void read(double &x){scanf("%lf", &x);}
inline void read(long double &x){
	double tmp; read(tmp); x = tmp;
}
template <class T>
inline void read(T *a, int n){
	g(i, 0, n) read(a[i]);
}

inline void write(int x){printf("%d", x);}
inline void write(LL x){printf("%I64d", x);}
inline void write(double x){printf("%.10lf", x);}
inline void write(long double x){printf("%.10lf", (double) x);}
template <class T>
inline void writeln(T x){write(x); putchar('\n');}
template <class T>
inline void writeln(T *a, int n){
	g(i, 0, n) write(a[i]); putchar('\n');
}
template <class T>
inline void writelnln(T *a, int n){
	g(i, 0, n) writeln(a[i]);
}

int n, m;
int a[1086];
double dp[1086][1086];

int main(){
	read(n); read(m); read(a + 1, n);
	f(i, 1, n) f(j, 1, n) dp[i][j] = (a[i] > a[j]);
	while(m--){
		int a, b; scanf("%d%d", &a, &b);
		f(i, 1, n) if(i != a && i != b){
			dp[i][a] = dp[i][b] = (dp[i][a] + dp[i][b]) / 2;
			dp[a][i] = dp[b][i] = (dp[a][i] + dp[b][i]) / 2;
		}
		dp[a][b] = dp[b][a] = 0.5;
	}
	double ans = 0;
	f(i, 1, n) f(j, i + 1, n) ans += dp[i][j];
	printf("%.10lf\n", ans);
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
const int TAM = 1e3 + 10;

int arr[TAM];
double p[TAM][TAM];

int main() {

	int n, m;

	cin >> n >> m;

	for ( int i = 0; i < n; i ++ ) cin >> arr[i];

	for ( int i = 0; i < n; i ++ )
		for ( int j = 0; j < n; j ++ )
			if ( arr[i] > arr[j] ) p[i][j] = 1.0;
			else p[i][j] = 0.0;

	int i, j;

	for ( int k = 0; k < m; k ++ ) {
		cin >> i >> j;
		i --; j --;
		if ( i > j ) swap ( i, j );
		p[i][j] = 0.5;
		for ( int l = 0; l < n; l ++ ) {
			if ( l == i || l == j ) continue;
			p[i][l] = p[j][l] = 0.5 * p[i][l] + 0.5 * p[j][l];
			p[l][i] = p[l][j] = 1.0 - p[i][l];
		}
	}

	double ans = 0.0;

	for ( i = 0; i < n; i ++ )
		for ( j = i + 1; j < n; j ++ )
			ans += p[i][j];

	cout << fixed << setprecision(13) << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
const int TAM = 1e3 + 10;

int arr[TAM];
double p[TAM][TAM];

int main() {

	int n, m;

	cin >> n >> m;

	for ( int i = 0; i < n; i ++ ) cin >> arr[i];

	for ( int i = 0; i < n; i ++ )
		for ( int j = 0; j < n; j ++ )
			if ( arr[i] > arr[j] ) p[i][j] = 1.0;
			else p[i][j] = 0.0;

	int i, j;

	for ( int k = 0; k < m; k ++ ) {
		cin >> i >> j;
		i --; j --;
		if ( i > j ) swap ( i, j );
		p[i][j] = 0.5;
		for ( int l = 0; l < n; l ++ ) {
			if ( l == i || l == j ) continue;
			p[i][l] = p[j][l] = ( p[i][l] + p[j][l] ) / 2.0;
			p[l][i] = p[l][j] = 1.0 - p[i][l];
		}
	}

	double ans = 0.0;

	for ( i = 0; i < n; i ++ )
		for ( j = i + 1; j < n; j ++ )
			ans += p[i][j];

	cout << fixed << setprecision(13) << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
const int TAM = 1e3 + 10;

int arr[TAM];
double p[TAM][TAM];

int main() {

	int n, m;

	cin >> n >> m;

	for ( int i = 0; i < n; i ++ ) cin >> arr[i];

	for ( int i = 0; i < n; i ++ )
		for ( int j = 0; j < n; j ++ )
			if ( arr[i] > arr[j] ) p[i][j] = 1.0;
			else p[i][j] = 0.0;

	int i, j;

	for ( int k = 0; k < m; k ++ ) {
		cin >> i >> j;
		i --; j --;
		if ( i > j ) swap ( i, j );
		p[i][j] = p[j][i] = 0.5;
		for ( int l = 0; l < n; l ++ ) {
			if ( l == i || l == j ) continue;
			p[i][l] = p[j][l] = ( p[i][l] + p[j][l] ) / 2.0;
			p[l][i] = p[l][j] = 1.0 - p[i][l];
		}
	}

	double ans = 0.0;

	for ( i = 0; i < n; i ++ )
		for ( j = i + 1; j < n; j ++ )
			ans += p[i][j];

	cout << fixed << setprecision(13) << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

double Dp[1010][1010], tmp;

int S[1010], x, y;

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++) scanf("%d", &S[i]);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			if(S[i] > S[j]) Dp[i][j] = 1;
	while(m--) {
		scanf("%d%d", &x, &y);
		for(int i = 1; i <= n; i++) if(i != x && i != y) tmp = Dp[i][x] + Dp[i][y], Dp[i][x] = Dp[i][y] = tmp / 2;
		for(int i = 1; i <= n; i++) if(i != x && i != y) Dp[x][i] = 1 - Dp[i][x], Dp[y][i] = 1 - Dp[i][y];
		Dp[x][y] = Dp[y][x] = 0.5;
	}
	double ans = 0;
	for(int i = 1; i <= n; i++)
		for(int j = i + 1; j <= n; j++)
			ans += Dp[i][j];
	printf("%.12lf\n", ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
double Dp[1010][1010], tmp;
int S[1010], x, y, n, m;
int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++) scanf("%d", &S[i]);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++) Dp[i][j] = (S[i] > S[j]);
	while(m--) {
		scanf("%d%d", &x, &y);
		for(int i = 1; i <= n; i++) if(i != x && i != y) tmp = Dp[i][x] + Dp[i][y], Dp[i][x] = Dp[i][y] = tmp / 2, Dp[x][i] = Dp[y][i] = 1 - tmp / 2;
		Dp[x][y] = Dp[y][x] = 0.5;
	}
	double ans = 0;
	for(int i = 1; i <= n; i++)
		for(int j = i + 1; j <= n; j++) ans += Dp[i][j];
	printf("%.12lf\n", ans);
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <memory.h>

const int MAXN = 1010;

using namespace std;

double p[MAXN][MAXN];
int arr[MAXN];
int n, m;

int main() {
  memset(p, 0.0, sizeof p);

  scanf("%d%d", &n, &m);

  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    arr[i]--;
  }

  memset(p, 0.0, sizeof p);
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      if  (arr[i] > arr[j])
        p[i][j] = 1.0;

  for (int it = 0; it < m; it++) {
    int a, b; scanf("%d%d", &a, &b); a--; b--;
    if  (a > b) swap(a, b);

    p[a][b] = 0.5;

    for (int c = 0; c < a; c++) {
      double pa = p[c][a];
      double pb = p[c][b];
      p[c][a] = p[c][b] = 0.5 * pa + 0.5 * pb;
    }

    for (int c = a + 1; c < b; c++) {
     double pa = p[a][c];
     double pb = p[c][b];
     p[a][c] = 0.5 * pa + 0.5 * (1.0 - pb);
     p[c][b] = 0.5 * (1.0 - pa) + 0.5 * pb;
    }

    for (int c = b + 1; c < n; c++) {
      double pa = p[a][c];
      double pb = p[b][c];
      p[a][c] = p[b][c] = 0.5 * pa + 0.5 * pb;
    }
  }

  double res = 0.0;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      res += p[i][j];

  printf("%.10lf\n", res);
  return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <math.h>
#include <cstdlib>
#include <memory.h>
#include <queue>
#include <assert.h>

#define pb push_back
#define LL long long
#define uLL unsigned long long
#define mp make_pair
#define pii pair <int,int>
#define sz(A) ((int)(A).size())
#define y1 qwertyuiopasdfghjklzxcvbnm
#define y0 ehfoiuvhefroerferjhfjkehfjke

const double EPS = 1e-9;
const double PI = acos(-1.0);
const int MAXN = 1010;

using namespace std;

double p[MAXN][MAXN];
int arr[MAXN];
int n, m;

int main() {
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  memset(p, 0.0, sizeof p);

  cin >> n >> m;

  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    arr[i]--;
  }

  memset(p, 0.0, sizeof p);
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      if  (arr[i] < arr[j])
        p[i][j] = 1.0;
      else
        p[j][i] = 1.0;

  for (int it = 0; it < m; it++) {
    int a, b; scanf("%d%d", &a, &b); a--; b--;

    p[a][b] = p[b][a] = 0.5;
    for (int other = 0; other < n; other++) {
      if  (other == a || other == b) continue;
      double pa = p[a][other];
      double pb = p[b][other];

      p[a][other] = p[b][other] = 0.5 * pb + 0.5 * pa;
      p[other][a] = p[other][b] = 1.0 - 0.5 * pb - 0.5 * pa;
    }
  }

  double res = 0.0;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      res += p[j][i];

  printf("%.10lf\n", res);
  return 0;
}


#include <cstdio>
#include <vector>
#include <cstring>
#include <functional>
#include <algorithm>
#include <math.h>
#include <bitset>
#include <set>
#include <queue>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <complex>
#include <numeric>
#include <map>
#include <time.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef pair<pii,ll> ppl;
typedef pair<ll,pii> plp;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;
typedef pair<double,int> pdi;
typedef pair<double,pii> pdp;
typedef pair<double,double> pdd;
typedef pair<pdd,double> pd3;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i,n) for (int (i) = 0; (i) < (n); (i)++)
#define repn(i,a,n) for (int (i) = (a); (i) < (n); (i)++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define SORT(x) sort((x).begin(),(x).end())
#define SORTN(x,n) sort((x),(x)+(n))
#define ERASE(x) (x).erase(unique((x).begin(),(x).end()),(x).end())
#define COUNT(x,c) count((x).begin(),(x).end(),(c))
#define REMOVE(x,c) (x).erase(remove((x).begin(),(x).end(),(c)),(x).end())
#define REVERSE(x) reverse((x).begin(),(x).end())
#define FORIT(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))-(x).begin()
#define lb(x,a) lower_bound((x).begin(),(x).end(),(a))
#define LBN(x,a,n) lower_bound((x),(x)+(n),(a))-(x)
#define lbN(x,a,n) lower_bound((x),(x)+(n),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))-(x).begin()
#define ub(x,a) upper_bound((x).begin(),(x).end(),(a))
#define BS(x,a) binary_search((x).begin(),(x).end(),(a))
#define BS2(x,n,a) binary_search((x),(x)+(n),(a))
#define NB(x) (((x)&~((x)+((x)&-(x))))/((x)&-(x))>>1)|((x)+((x)&-(x)))
#define NP(x) next_permutation((x).begin(),(x).end())
#define MM(x,p) memset((x),(p),sizeof(x))
#define SQ(x) (x)*(x)
#define SC(c1,c2) strcmp(c1,c2)==0
#define mp make_pair
#define INF (1<<29)
#define INFL (1LL<<61)
#define fi first
#define se second
#define MOD 1000000007
#define EPS 1e-12
#define MIN(x,a) x=min(x,a)
#define MAX(x,a) x=max(x,a)
#define madd(x,a) x=(x+a)%MOD
#define msub(x,a) x=(x+MOD-a)%MOD
#define OUTPUT(x) rep(i,x.size())printf("%d%c",x[i],i+1==x.size()?'\n':' ');

//cf 157

int N,M,A,B;
int D[1000];
double dp[1000][1000];

int main()
{
    scanf("%d%d",&N,&M);
    rep(i,N)scanf("%d",&D[i]);
    rep(i,N)rep(j,N)if(D[i]>D[j])dp[i][j]=1;
    while(M--)
    {
        scanf("%d%d",&A,&B);A--,B--;
        rep(i,N)if(i!=A&&i!=B)
        {
            dp[i][A]=dp[i][B]=(dp[i][A]+dp[i][B])/2;
            dp[A][i]=dp[B][i]=(dp[A][i]+dp[B][i])/2;
        }
        dp[A][A]=dp[B][B]=0;
        dp[A][B]=dp[B][A]=(dp[A][B]+dp[B][A])/2;
    }
    double res=0;
    rep(i,N)rep(j,i)res+=dp[i][j];
    printf("%.12f\n",res);
}