#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <limits.h>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <cstring>
using namespace std;
#define rep(i, n) for (int (i) = 0, j123 = n; (i) < j123; (i) ++)
#define rep1(i, n) for (int (i) = 1, j123 = n; (i) <= j123; (i) ++)
#define db(x) {cout << #x << " = " << (x) << endl;}
#define dba(a, x, y) {cout << #a << " :";for(int i123=(x);i123<=(y);i123++) cout<<setw(4)<<(a)[i123];cout<<endl;}
#define clr(x) memset(x,0,sizeof(x));
#define mp make_pair
#define pb push_back
#define sz(x) int(x.size())
#define endl '\n'
typedef long long ll;
typedef long double ld;
const int INF = INT_MAX;
const ll INFL = LLONG_MAX;
const ld pi = acos(-1);
// const int MOD = ;

ll n, d, x;
ll a[100100];
ll b[100100];
ll sumb[100100];
//x is 64-bit variable;
int getNextX() {
  x = (x * 37 + 10007) % 1000000007;
  return x;
}
int 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 loc[100100];
int main()
{
  ios_base::sync_with_stdio(0); cout.precision(15); cout << fixed; cout.tie(0); cin.tie(0);
  cin >> n >> d >> x;
  initAB();
  for (int i = 0; i < n; i++)
    loc[a[i]] = i;
  for (int i = 0; i < n; i++)
    if (i > 0)
      sumb[i] = b[i] + sumb[i-1];
  for (int i = 0; i < n; i++)
  {
    // calculate c[i]
    ll ans = -1e10;
    if (sumb[i] < 1e3)
    {
      // bruteforce
      for (int j = 0; j <= i; j++)
        ans = max(ans, a[j] * b[i-j]);
    }
    else
    {
      for (int x = n-1; i >= 0; i--)
      {
        int j = loc[x];
        if (0 <= j && j <= i)
        {
          if (b[i-j] == 1)
          {
            ans = x;
            break;
          }
        }
      }
    }
    cout << ans << endl;
  }
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <limits.h>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <cstring>
using namespace std;
#define rep(i, n) for (int (i) = 0, j123 = n; (i) < j123; (i) ++)
#define rep1(i, n) for (int (i) = 1, j123 = n; (i) <= j123; (i) ++)
#define db(x) {cout << #x << " = " << (x) << endl;}
#define dba(a, x, y) {cout << #a << " :";for(int i123=(x);i123<=(y);i123++) cout<<setw(4)<<(a)[i123];cout<<endl;}
#define clr(x) memset(x,0,sizeof(x));
#define mp make_pair
#define pb push_back
#define sz(x) int(x.size())
#define endl '\n'
typedef long long ll;
typedef long double ld;
const int INF = INT_MAX;
const ll INFL = LLONG_MAX;
const ld pi = acos(-1);
// const int MOD = ;

ll n, d, x;
ll a[100100];
ll b[100100];
ll sumb[100100];
//x is 64-bit variable;
int getNextX() {
  x = (x * 37 + 10007) % 1000000007;
  return x;
}
int 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 loc[100100];
int main()
{
  ios_base::sync_with_stdio(0); cout.precision(15); cout << fixed; cout.tie(0); cin.tie(0);
  cin >> n >> d >> x;
  initAB();
  for (int i = 0; i < n; i++)
    loc[a[i]] = i;
  for (int i = 0; i < n; i++)
    if (i > 0)
      sumb[i] = b[i] + sumb[i-1];
  vector<int> indexForB;
  for (int i = 0; i < n; i++)
    if (b[i] > 0)
      indexForB.pb(i);

  priority_queue< pair<int,int> > pq;
  for (int i = 0; i < n; i++)
  {
    // calculate c[i]
    ll ans = 0;
    pq.push(mp(a[i],i));
    if (sumb[i] < 3e2)
    {
      // bruteforce
      for (int ii = 0; ii < sz(indexForB); ii++)
      {
        int ind = indexForB[ii];
        if (ind <= i)
        {
          ans = max(ans, a[i-ind]);
        }
        else
        {
          break;
        }
      }
    }
    else
    {
      stack< pair<int,int> > stk;
      while (!pq.empty())
      {
        int Aj = pq.top().first;
        int j = pq.top().second;
        pq.pop();
        stk.push(mp(Aj,j));
        if (b[i-j] == 1)
        {
          ans = Aj;
          while (!stk.empty())
          {
            pq.push(stk.top());
            stk.pop();
          }
          break;
        }
      }
    }
    cout << ans << endl;
  }
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <limits.h>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <cstring>
using namespace std;
#define rep(i, n) for (int (i) = 0, j123 = n; (i) < j123; (i) ++)
#define rep1(i, n) for (int (i) = 1, j123 = n; (i) <= j123; (i) ++)
#define db(x) {cout << #x << " = " << (x) << endl;}
#define dba(a, x, y) {cout << #a << " :";for(int i123=(x);i123<=(y);i123++) cout<<setw(4)<<(a)[i123];cout<<endl;}
#define clr(x) memset(x,0,sizeof(x));
#define mp make_pair
#define pb push_back
#define sz(x) int(x.size())
#define endl '\n'
typedef long long ll;
typedef long double ld;
const int INF = INT_MAX;
const ll INFL = LLONG_MAX;
const ld pi = acos(-1);
// const int MOD = ;

ll n, d, x;
ll a[100100];
ll b[100100];
ll sumb[100100];
//x is 64-bit variable;
int getNextX() {
  x = (x * 37 + 10007) % 1000000007;
  return x;
}
int 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 loc[100100];
int main()
{
  ios_base::sync_with_stdio(0); cout.precision(15); cout << fixed; cout.tie(0); cin.tie(0);
  cin >> n >> d >> x;
  initAB();
  for (int i = 0; i < n; i++)
    loc[a[i]] = i;
  for (int i = 0; i < n; i++)
    if (i > 0)
      sumb[i] = b[i] + sumb[i-1];
  vector<int> indexForB;
  for (int i = 0; i < n; i++)
    if (b[i] > 0)
      indexForB.pb(i);

  priority_queue< pair<int,int> > pq;
  for (int i = 0; i < n; i++)
  {
    // calculate c[i]
    ll ans = 0;
    pq.push(mp(a[i],i));
    if (sumb[i] < 5e3)
    {
      // bruteforce
      for (int ii = 0; ii < sz(indexForB); ii++)
      {
        int ind = indexForB[ii];
        if (ind <= i)
        {
          ans = max(ans, a[i-ind]);
        }
        else
        {
          break;
        }
      }
    }
    else
    {
      stack< pair<int,int> > stk;
      while (!pq.empty())
      {
        int Aj = pq.top().first;
        int j = pq.top().second;
        pq.pop();
        stk.push(mp(Aj,j));
        if (b[i-j] == 1)
        {
          ans = Aj;
          while (!stk.empty())
          {
            pq.push(stk.top());
            stk.pop();
          }
          break;
        }
      }
    }
    cout << ans << endl;
  }
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <limits.h>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <cstring>
using namespace std;
#define rep(i, n) for (int (i) = 0, j123 = n; (i) < j123; (i) ++)
#define rep1(i, n) for (int (i) = 1, j123 = n; (i) <= j123; (i) ++)
#define db(x) {cout << #x << " = " << (x) << endl;}
#define dba(a, x, y) {cout << #a << " :";for(int i123=(x);i123<=(y);i123++) cout<<setw(4)<<(a)[i123];cout<<endl;}
#define clr(x) memset(x,0,sizeof(x));
#define mp make_pair
#define pb push_back
#define sz(x) int(x.size())
#define endl '\n'
typedef long long ll;
typedef long double ld;
const int INF = INT_MAX;
const ll INFL = LLONG_MAX;
const ld pi = acos(-1);
// const int MOD = ;

ll n, d, x;
ll a[100100];
ll b[100100];
ll sumb[100100];
//x is 64-bit variable;
int getNextX() {
  x = (x * 37 + 10007) % 1000000007;
  return x;
}
int 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 loc[100100];
int main()
{
  ios_base::sync_with_stdio(0); cout.precision(15); cout << fixed; cout.tie(0); cin.tie(0);
  cin >> n >> d >> x;
  initAB();
  for (int i = 0; i < n; i++)
    loc[a[i]] = i;
  for (int i = 0; i < n; i++)
    if (i > 0)
      sumb[i] = b[i] + sumb[i-1];
  vector<int> indexForB;
  for (int i = 0; i < n; i++)
    if (b[i] > 0)
      indexForB.pb(i);

  for (int i = 0; i < n; i++)
  {
    // calculate c[i]
    ll ans = 0;
    if (sumb[i] < 1e3)
    {
      // bruteforce
      for (int ii = 0; ii < sz(indexForB); ii++)
      {
        int ind = indexForB[ii];
        if (ind <= i)
        {
          ans = max(ans, a[i-ind]);
        }
        else
        {
          break;
        }
      }
    }
    else
    {
      for (int x = n-1; i >= 0; i--)
      {
        int j = loc[x];
        if (0 <= j && j <= i)
        {
          if (b[i-j] == 1)
          {
            ans = x;
            break;
          }
        }
      }
    }
    cout << ans << endl;
  }
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <limits.h>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <cstring>
using namespace std;
#define rep(i, n) for (int (i) = 0, j123 = n; (i) < j123; (i) ++)
#define rep1(i, n) for (int (i) = 1, j123 = n; (i) <= j123; (i) ++)
#define db(x) {cout << #x << " = " << (x) << endl;}
#define dba(a, x, y) {cout << #a << " :";for(int i123=(x);i123<=(y);i123++) cout<<setw(4)<<(a)[i123];cout<<endl;}
#define clr(x) memset(x,0,sizeof(x));
#define mp make_pair
#define pb push_back
#define sz(x) int(x.size())
#define endl '\n'
typedef long long ll;
typedef long double ld;
const int INF = INT_MAX;
const ll INFL = LLONG_MAX;
const ld pi = acos(-1);
// const int MOD = ;

ll n, d, x;
ll a[100100];
ll b[100100];
ll sumb[100100];
//x is 64-bit variable;
int getNextX() {
  x = (x * 37 + 10007) % 1000000007;
  return x;
}
int 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 loc[100100];
int main()
{
  ios_base::sync_with_stdio(0); cout.precision(15); cout << fixed; cout.tie(0); cin.tie(0);
  cin >> n >> d >> x;
  initAB();
  for (int i = 0; i < n; i++)
    loc[a[i]] = i;
  for (int i = 0; i < n; i++)
    if (i > 0)
      sumb[i] = b[i] + sumb[i-1];
  vector<int> indexForB;
  for (int i = 0; i < n; i++)
    if (b[i] > 0)
      indexForB.pb(i);

  for (int i = 0; i < n; i++)
  {
    // calculate c[i]
    ll ans = 0;
    if (sumb[i] < 5e3)
    {
      // bruteforce
      for (int ii = 0; ii < sz(indexForB); ii++)
      {
        int ind = indexForB[ii];
        if (ind <= i)
        {
          ans = max(ans, a[i-ind]);
        }
        else
        {
          break;
        }
      }
    }
    else
    {
      for (int x = n-1; i >= 0; i--)
      {
        int j = loc[x];
        if (0 <= j && j <= i)
        {
          if (b[i-j] == 1)
          {
            ans = x;
            break;
          }
        }
      }
    }
    cout << ans << endl;
  }
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <limits.h>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <cstring>
using namespace std;
#define rep(i, n) for (int (i) = 0, j123 = n; (i) < j123; (i) ++)
#define rep1(i, n) for (int (i) = 1, j123 = n; (i) <= j123; (i) ++)
#define db(x) {cout << #x << " = " << (x) << endl;}
#define dba(a, x, y) {cout << #a << " :";for(int i123=(x);i123<=(y);i123++) cout<<setw(4)<<(a)[i123];cout<<endl;}
#define clr(x) memset(x,0,sizeof(x));
#define mp make_pair
#define pb push_back
#define sz(x) int(x.size())
#define endl '\n'
typedef long long ll;
typedef long double ld;
const int INF = INT_MAX;
const ll INFL = LLONG_MAX;
const ld pi = acos(-1);
// const int MOD = ;

ll n, d, x;
ll a[100100];
ll b[100100];
ll sumb[100100];
//x is 64-bit variable;
int getNextX() {
  x = (x * 37 + 10007) % 1000000007;
  return x;
}
int 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 loc[100100];
int main()
{
  ios_base::sync_with_stdio(0); cout.precision(15); cout << fixed; cout.tie(0); cin.tie(0);
  cin >> n >> d >> x;
  initAB();
  for (int i = 0; i < n; i++)
    loc[a[i]] = i;
  for (int i = 0; i < n; i++)
    if (i > 0)
      sumb[i] = b[i] + sumb[i-1];
  vector<int> indexForB;
  for (int i = 0; i < n; i++)
    if (b[i] > 0)
      indexForB.pb(i);

  for (int i = 0; i < n; i++)
  {
    // calculate c[i]
    ll ans = -1e10;
    if (sumb[i] < 1e3)
    {
      // bruteforce
      for (int ii = 0; ii < sz(indexForB); ii++)
      {
        int ind = indexForB[ii];
        if (ind <= i)
        {
          ans = max(ans, a[i-ind]);
        }
        else
        {
          break;
        }
      }
    }
    else
    {
      for (int x = n-1; i >= 0; i--)
      {
        int j = loc[x];
        if (0 <= j && j <= i)
        {
          if (b[i-j] == 1)
          {
            ans = x;
            break;
          }
        }
      }
    }
    cout << ans << endl;
  }
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <limits.h>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <cstring>
using namespace std;
#define rep(i, n) for (int (i) = 0, j123 = n; (i) < j123; (i) ++)
#define rep1(i, n) for (int (i) = 1, j123 = n; (i) <= j123; (i) ++)
#define db(x) {cout << #x << " = " << (x) << endl;}
#define dba(a, x, y) {cout << #a << " :";for(int i123=(x);i123<=(y);i123++) cout<<setw(4)<<(a)[i123];cout<<endl;}
#define clr(x) memset(x,0,sizeof(x));
#define mp make_pair
#define pb push_back
#define sz(x) int(x.size())
#define endl '\n'
typedef long long ll;
typedef long double ld;
const int INF = INT_MAX;
const ll INFL = LLONG_MAX;
const ld pi = acos(-1);
// const int MOD = ;

ll n, d, x;
ll a[100100];
ll b[100100];
ll sumb[100100];
//x is 64-bit variable;
int getNextX() {
  x = (x * 37 + 10007) % 1000000007;
  return x;
}
int 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 loc[100100];
int main()
{
  ios_base::sync_with_stdio(0); cout.precision(15); cout << fixed; cout.tie(0); cin.tie(0);
  cin >> n >> d >> x;
  initAB();
  for (int i = 0; i < n; i++)
    loc[a[i]] = i;
  for (int i = 0; i < n; i++)
    if (i > 0)
      sumb[i] = b[i] + sumb[i-1];
  vector<int> indexForB;
  for (int i = 0; i < n; i++)
    if (b[i] > 0)
      indexForB.pb(i);

  for (int i = 0; i < n; i++)
  {
    // calculate c[i]
    ll ans = 0;
    if (sumb[i] < 5e2)
    {
      // bruteforce
      for (int ii = 0; ii < sz(indexForB); ii++)
      {
        int ind = indexForB[ii];
        if (ind <= i)
        {
          ans = max(ans, a[i-ind]);
        }
        else
        {
          break;
        }
      }
    }
    else
    {
      for (int x = n-1; i >= 0; i--)
      {
        int j = loc[x];
        if (0 <= j && j <= i)
        {
          if (b[i-j] == 1)
          {
            ans = x;
            break;
          }
        }
      }
    }
    cout << ans << endl;
  }
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#define FOR(i,a,b) for(i=a; i<=b; i++)
#define FOR2(i,n) FOR(i,0,n-1)
#define TFOR(i,a,b) for(i=a; i>=b; i--)
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define MAXN 1005
using namespace std;
typedef pair < int , int > pii;
int read(){ int res(0),sign(1); char c;
	while(1){ c = getchar(); if('0' <= c && c <= '9') { res = c - '0'; break; } else if(c == '-') { sign = -1; break; } }
	while(1){ c = getchar(); if('0' <= c && c <= '9') res = res*10 + c - '0'; else break; }
	return res * sign;
}
long long x;
int A[MAXN] , B[MAXN];
int f()
{
	x = (x * 37 + 10007) % 1000000007;
	return x;
}
set < pii > st;
int D,N;
int res[MAXN];
int main()
{
	int i;
	N = read(); D = read(); x = read();
	FOR2(i,N) A[i] = i + 1;
    FOR2(i,N) swap(A[i], A[f() % (i + 1)]);
    FOR2(i,N) B[i] = (i<D);
	FOR2(i,N) swap(B[i], B[f() % (i + 1)]);

	set < pii > :: iterator it;
	FOR2(i,N)
	{
		st.insert( make_pair( -A[i] , i ) );
		for(it = st.begin(); it != st.end(); ++it)
			if( it->s <= i && B[i-it->s] )
			{
				res[i] = -it->f;
				break;
			}
	}

	FOR2(i,N)
		printf("%d\n" , res[i] );

	return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#define FOR(i,a,b) for(i=a; i<=b; i++)
#define FOR2(i,n) FOR(i,0,n-1)
#define TFOR(i,a,b) for(i=a; i>=b; i--)
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define MAXN 100005
using namespace std;
typedef pair < int , int > pii;
int read(){ int res(0),sign(1); char c;
	while(1){ c = getchar(); if('0' <= c && c <= '9') { res = c - '0'; break; } else if(c == '-') { sign = -1; break; } }
	while(1){ c = getchar(); if('0' <= c && c <= '9') res = res*10 + c - '0'; else break; }
	return res * sign;
}
long long x;
int A[MAXN] , B[MAXN];
int f()
{
	x = (x * 37 + 10007) % 1000000007;
	return x;
}
set < pii > st;
int D,N;
int res[MAXN];
int main()
{
	int i;
	N = read(); D = read(); x = read();
	FOR2(i,N) A[i] = i + 1;
    FOR2(i,N) swap(A[i], A[f() % (i + 1)]);
    FOR2(i,N) B[i] = (i<D);
	FOR2(i,N) swap(B[i], B[f() % (i + 1)]);

	set < pii > :: iterator it;
	FOR2(i,N)
	{
		st.insert( make_pair( -A[i] , i ) );
		for(it = st.begin(); it != st.end(); ++it)
			if( it->s <= i && B[i-it->s] )
			{
				res[i] = -it->f;
				break;
			}
	}

	FOR2(i,N)
		printf("%d\n" , res[i] );

	return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#define FOR(i,a,b) for(i=a; i<=b; i++)
#define FOR2(i,n) FOR(i,0,n-1)
#define TFOR(i,a,b) for(i=a; i>=b; i--)
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define MAXN 100005
using namespace std;
typedef pair < int , int > pii;
int read(){ int res(0),sign(1); char c;
	while(1){ c = getchar(); if('0' <= c && c <= '9') { res = c - '0'; break; } else if(c == '-') { sign = -1; break; } }
	while(1){ c = getchar(); if('0' <= c && c <= '9') res = res*10 + c - '0'; else break; }
	return res * sign;
}
long long x;
int f()
{
	x = (x * 37 + 10007) % 1000000007;
	return x;
}
set < pii > st;
vector < int > V;
int D,N;
int A[MAXN] , B[MAXN] , res[MAXN];
int main()
{
	int i;
	N = read(); D = read(); x = read();
	FOR2(i,N) A[i] = i + 1;
    FOR2(i,N) swap(A[i], A[f() % (i + 1)]);
    FOR2(i,N) B[i] = (i<D);
	FOR2(i,N)
		swap(B[i], B[f() % (i + 1)]);

	FOR2(i,N)
		if(B[i])
			V.pb(i);

	set < pii > :: iterator it;
	vector < int > :: iterator it2;
	FOR2(i,N)
	{
		if(D <= 350)
		{
			for(it2 = V.begin(); it2 != V.end(); ++it2)
				if(*it2 <= i)
					res[i] = max( res[i] , A[ i-(*it2) ] );
		}
		else
		{
			st.insert( make_pair( -A[i] , i ) );
			for(it = st.begin(); it != st.end(); ++it)
				if( it->s <= i && B[i-it->s] )
				{
					res[i] = -it->f;
					break;
				}
		}
	}

	FOR2(i,N)
		printf("%d\n" , res[i] );

	return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#define FOR(i,a,b) for(i=a; i<=b; i++)
#define FOR2(i,n) FOR(i,0,n-1)
#define TFOR(i,a,b) for(i=a; i>=b; i--)
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define MAXN 100005
using namespace std;
typedef pair < int , int > pii;
int read(){ int res(0),sign(1); char c;
	while(1){ c = getchar(); if('0' <= c && c <= '9') { res = c - '0'; break; } else if(c == '-') { sign = -1; break; } }
	while(1){ c = getchar(); if('0' <= c && c <= '9') res = res*10 + c - '0'; else break; }
	return res * sign;
}
long long x;
int f()
{
	x = (x * 37 + 10007) % 1000000007;
	return x;
}
set < pii > st;
vector < int > V;
int D,N;
int A[MAXN] , B[MAXN] , res[MAXN];
int main()
{
	int i;
	N = read(); D = read(); x = read();
	FOR2(i,N) A[i] = i + 1;
    FOR2(i,N) swap(A[i], A[f() % (i + 1)]);
    FOR2(i,N) B[i] = (i<D);
	FOR2(i,N)
	{
		swap(B[i], B[f() % (i + 1)]);
		if( B[i] ) V.pb(i);
	}

	set < pii > :: iterator it;
	vector < int > :: iterator it2;
	FOR2(i,N)
	{
		if(D <= 350)
		{
			for(it2 = V.begin(); it2 != V.end(); ++it2)
				if(*it2 <= i)
					res[i] = max( res[i] , A[ i-(*it2) ] );
		}
		else
		{
			st.insert( make_pair( -A[i] , i ) );
			for(it = st.begin(); it != st.end(); ++it)
				if( it->s <= i && B[i-it->s] )
				{
					res[i] = -it->f;
					break;
				}
		}
	}

	FOR2(i,N)
		printf("%d\n" , res[i] );

	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long x;
int n,d,a[1000005],b[1000005],maxv[101],mn,nn,one[1000005],c[1000005];
bool cmp(const int &i,const int &j){return a[i]>a[j];}

int 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)]);
    }
}
int main(){
	scanf("%d%d%I64d",&n,&d,&x);
	initAB();
	for (int i=0;i<n;i++){
		if (b[i]==1) one[++nn]=i;
		maxv[++mn]=i;
		sort(maxv+1,maxv+mn+1,cmp);
		if (mn==431) mn--;
		if (nn<=300){
			for (int j=1;j<=nn;j++)
				c[i]=max(c[i],a[i-one[j]]);
		}
		else{
			for (int j=1;j<=mn;j++)
				if (b[i-maxv[j]]==1){
					c[i]=a[maxv[j]];break;
				}
		}
	}
	for (int i=0;i<n;i++) printf("%d\n",c[i]);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long x;
int n,d,a[1000005],b[1000005],maxv[101],mn,nn,one[1000005],c[1000005];
bool cmp(const int &i,const int &j){return a[i]>a[j];}

int 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)]);
    }
}
int main(){
	scanf("%d%d%I64d",&n,&d,&x);
	initAB();
	for (int i=0;i<n;i++){
		if (b[i]==1) one[++nn]=i;
		maxv[++mn]=i;
		sort(maxv+1,maxv+mn+1,cmp);
		if (mn==401) mn--;
		if (nn<=400){
			for (int j=1;j<=nn;j++)
				c[i]=max(c[i],a[i-one[j]]);
		}
		else{
			for (int j=1;j<=mn;j++)
				if (b[i-maxv[j]]==1){
					c[i]=a[maxv[j]];break;
				}
		}
	}
	for (int i=0;i<n;i++) printf("%d\n",c[i]);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long x;
int n,d,a[1000005],b[1000005],maxv[101],mn,nn,one[1000005],c[1000005];
bool cmp(const int &i,const int &j){return a[i]>a[j];}

int 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)]);
    }
}
int main(){
	scanf("%d%d%I64d",&n,&d,&x);
	initAB();
	for (int i=0;i<n;i++){
		if (b[i]==1) one[++nn]=i;
		maxv[++mn]=i;
		sort(maxv+1,maxv+mn+1,cmp);
		if (mn==401) mn--;
		c[i]=-1;
		for (int j=1;j<=mn;j++)
			if (b[i-maxv[j]]==1){
				c[i]=a[maxv[j]];break;
			}
		if (c[i]==-1)
		for (int j=1;j<=nn;j++)
			c[i]=max(c[i],a[i-one[j]]);
	}
	for (int i=0;i<n;i++) printf("%d\n",c[i]);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long x;
int n,d,a[1000005],b[1000005],maxv[101],mn,nn,one[1000005],c[1000005];
bool cmp(const int &i,const int &j){return a[i]>a[j];}

int 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)]);
    }
}
int main(){
	scanf("%d%d%I64d",&n,&d,&x);
	initAB();
	for (int i=0;i<n;i++){
		if (b[i]==1) one[++nn]=i;
		maxv[++mn]=i;
		sort(maxv+1,maxv+mn+1,cmp);
		if (mn==501) mn--;
		if (nn<=300){
			for (int j=1;j<=nn;j++)
				c[i]=max(c[i],a[i-one[j]]);
		}
		else{
			for (int j=1;j<=mn;j++)
				if (b[i-maxv[j]]==1){
					c[i]=a[maxv[j]];break;
				}
		}
	}
	for (int i=0;i<n;i++) printf("%d\n",c[i]);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long x;
int n,d,a[1000005],b[1000005],maxv[1001],mn,nn,one[1000005],c[1000005];

int 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)]);
    }
}
int main(){
	scanf("%d%d%I64d",&n,&d,&x);
	initAB();
	for (int i=0;i<n;i++){
		if (b[i]==1) one[++nn]=i;
		maxv[++mn]=i;int td=mn;
		while (td>1&&a[maxv[td-1]]<a[maxv[td]]){
			swap(maxv[td-1],maxv[td]);td--;
		}
		if (mn==1001) mn--;
		if (nn<=1500){
			for (int j=1;j<=nn;j++)
				c[i]=max(c[i],a[i-one[j]]);
		}
		else{
			for (int j=1;j<=mn;j++)
				if (b[i-maxv[j]]==1){
					c[i]=a[maxv[j]];break;
				}
		}
	}
	for (int i=0;i<n;i++) printf("%d\n",c[i]);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long x;
int n,d,a[1000005],b[1000005],maxv[1001],mn,nn,one[1000005],c[1000005];

int 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)]);
    }
}
int main(){
	scanf("%d%d%I64d",&n,&d,&x);
	initAB();
	for (int i=0;i<n;i++){
		if (b[i]==1) one[++nn]=i;
		maxv[++mn]=i;int td=mn;
		while (td>1&&a[maxv[td-1]]<a[maxv[td]]){
			swap(maxv[td-1],maxv[td]);td--;
		}
		if (mn==501) mn--;
		if (nn<=1000){
			for (int j=1;j<=nn;j++)
				c[i]=max(c[i],a[i-one[j]]);
		}
		else{
			for (int j=1;j<=mn;j++)
				if (b[i-maxv[j]]==1){
					c[i]=a[maxv[j]];break;
				}
		}
	}
	for (int i=0;i<n;i++) printf("%d\n",c[i]);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long x;
int n,d,a[1000005],b[1000005],maxv[1001],mn,nn,one[1000005],c[1000005];
bool cmp(const int &i,const int &j){return a[i]>a[j];}

int 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)]);
    }
}
int main(){
	scanf("%d%d%I64d",&n,&d,&x);
	initAB();
	for (int i=0;i<n;i++){
		if (b[i]==1) one[++nn]=i;
		maxv[++mn]=i;
		sort(maxv+1,maxv+mn+1,cmp);
		if (mn==401) mn--;
		c[i]=-1;
		for (int j=1;j<=mn;j++)
			if (b[i-maxv[j]]==1){
				c[i]=a[maxv[j]];break;
			}
		if (c[i]==-1)
		for (int j=1;j<=nn;j++)
			c[i]=max(c[i],a[i-one[j]]);
		c[i]=max(c[i],0);
	}
	for (int i=0;i<n;i++) printf("%d\n",c[i]);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long x;
int n,d,a[1000005],b[1000005],maxv[101],mn,nn,one[1000005],c[1000005];
bool cmp(const int &i,const int &j){return a[i]>a[j];}

int 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)]);
    }
}
int main(){
	scanf("%d%d%I64d",&n,&d,&x);
	initAB();
	for (int i=0;i<n;i++){
		if (b[i]==1) one[++nn]=i;
		maxv[++mn]=i;
		sort(maxv+1,maxv+mn+1,cmp);
		if (mn==501) mn--;
		if (nn<=500){
			for (int j=1;j<=nn;j++)
				c[i]=max(c[i],a[i-one[j]]);
		}
		else{
			for (int j=1;j<=mn;j++)
				if (b[i-maxv[j]]==1){
					c[i]=a[maxv[j]];break;
				}
		}
	}
	for (int i=0;i<n;i++) printf("%d\n",c[i]);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long x;
int n,d,a[1000005],b[1000005],maxv[1001],mn,nn,one[1000005],c[1000005];

int 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)]);
    }
}
int main(){
	scanf("%d%d%I64d",&n,&d,&x);
	initAB();
	for (int i=0;i<n;i++){
		if (b[i]==1) one[++nn]=i;
		maxv[++mn]=i;int td=mn;
		while (td>1&&a[maxv[td-1]]<a[maxv[td]]){
			swap(maxv[td-1],maxv[td]);td--;
		}
		if (mn==1001) mn--;
		if (nn<=1000){
			for (int j=1;j<=nn;j++)
				c[i]=max(c[i],a[i-one[j]]);
		}
		else{
			for (int j=1;j<=mn;j++)
				if (b[i-maxv[j]]==1){
					c[i]=a[maxv[j]];break;
				}
		}
	}
	for (int i=0;i<n;i++) printf("%d\n",c[i]);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long x;
int n,d,a[1000005],b[1000005],maxv[1001],mn,nn,one[1000005],c[1000005];

int 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)]);
    }
}
int main(){
	scanf("%d%d%I64d",&n,&d,&x);
	initAB();
	for (int i=0;i<n;i++){
		if (b[i]==1) one[++nn]=i;
		maxv[++mn]=i;int td=mn;
		while (td>1&&a[maxv[td-1]]<a[maxv[td]]){
			swap(maxv[td-1],maxv[td]);td--;
		}
		if (mn==401) mn--;
		if (nn<=1000){
			for (int j=1;j<=nn;j++)
				c[i]=max(c[i],a[i-one[j]]);
		}
		else{
			for (int j=1;j<=mn;j++)
				if (b[i-maxv[j]]==1){
					c[i]=a[maxv[j]];break;
				}
		}
	}
	for (int i=0;i<n;i++) printf("%d\n",c[i]);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long x;
int n,d,a[1000005],b[1000005],maxv[101],mn,nn,one[1000005],c[1000005];
bool cmp(const int &i,const int &j){return a[i]>a[j];}

int 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)]);
    }
}
int main(){
	scanf("%d%d%I64d",&n,&d,&x);
	initAB();
	for (int i=0;i<n;i++){
		if (b[i]==1) one[++nn]=i;
		maxv[++mn]=i;
		sort(maxv+1,maxv+mn+1,cmp);
		if (mn==501) mn--;
		if (nn<=400){
			for (int j=1;j<=nn;j++)
				c[i]=max(c[i],a[i-one[j]]);
		}
		else{
			for (int j=1;j<=mn;j++)
				if (b[i-maxv[j]]==1){
					c[i]=a[maxv[j]];break;
				}
		}
	}
	for (int i=0;i<n;i++) printf("%d\n",c[i]);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long x;
int n,d,a[1000005],b[1000005],maxv[1001],mn,nn,one[1000005],c[1000005];
bool cmp(const int &i,const int &j){return a[i]>a[j];}

int 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)]);
    }
}
int main(){
	scanf("%d%d%I64d",&n,&d,&x);
	initAB();
	for (int i=0;i<n;i++){
		if (b[i]==1) one[++nn]=i;
		maxv[++mn]=i;
		sort(maxv+1,maxv+mn+1,cmp);
		if (mn==401) mn--;
		if (nn<=400){
			for (int j=1;j<=nn;j++)
				c[i]=max(c[i],a[i-one[j]]);
		}
		else{
			for (int j=1;j<=mn;j++)
				if (b[i-maxv[j]]==1){
					c[i]=a[maxv[j]];break;
				}
		}
	}
	for (int i=0;i<n;i++) printf("%d\n",c[i]);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long x;
int n,d,a[1000005],b[1000005],maxv[1001],mn,nn,one[1000005],c[1000005];

int 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)]);
    }
}
int main(){
	scanf("%d%d%I64d",&n,&d,&x);
	initAB();
	for (int i=0;i<n;i++){
		if (b[i]==1) one[++nn]=i;
		maxv[++mn]=i;int td=mn;
		while (td>1&&a[maxv[td-1]]<a[maxv[td]]){
			swap(maxv[td-1],maxv[td]);td--;
		}
		if (mn==501) mn--;
		if (nn<=2000){
			for (int j=1;j<=nn;j++)
				c[i]=max(c[i],a[i-one[j]]);
		}
		else{
			for (int j=1;j<=mn;j++)
				if (b[i-maxv[j]]==1){
					c[i]=a[maxv[j]];break;
				}
		}
	}
	for (int i=0;i<n;i++) printf("%d\n",c[i]);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long x;
int n,d,a[1000005],b[1000005],maxv[101],mn,nn,one[1000005],c[1000005];
bool cmp(const int &i,const int &j){return a[i]>a[j];}

int 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)]);
    }
}
int main(){
	scanf("%d%d%I64d",&n,&d,&x);
	initAB();
	for (int i=0;i<n;i++){
		if (b[i]==1) one[++nn]=i;
		maxv[++mn]=i;
		sort(maxv+1,maxv+mn+1,cmp);
		if (mn==401) mn--;
		c[i]=-1;
		for (int j=1;j<=mn;j++)
			if (b[i-maxv[j]]==1){
				c[i]=a[maxv[j]];break;
			}
		if (c[i]==-1)
		for (int j=1;j<=nn;j++)
			c[i]=max(c[i],a[i-one[j]]);
		c[i]=max(c[i],0);
	}
	for (int i=0;i<n;i++) printf("%d\n",c[i]);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long x;
int n,d,a[1000005],b[1000005],maxv[1001],mn,nn,one[1000005],c[1000005];

int 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)]);
    }
}
int main(){
	scanf("%d%d%I64d",&n,&d,&x);
	initAB();
	for (int i=0;i<n;i++){
		if (b[i]==1) one[++nn]=i;
		maxv[++mn]=i;int td=mn;
		while (td>1&&a[maxv[td-1]]<a[maxv[td]]){
			swap(maxv[td-1],maxv[td]);td--;
		}
		if (mn==501) mn--;
		if (nn<=800){
			for (int j=1;j<=nn;j++)
				c[i]=max(c[i],a[i-one[j]]);
		}
		else{
			for (int j=1;j<=mn;j++)
				if (b[i-maxv[j]]==1){
					c[i]=a[maxv[j]];break;
				}
		}
	}
	for (int i=0;i<n;i++) printf("%d\n",c[i]);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long x;
int n,d,a[1000005],b[1000005],maxv[1001],mn,nn,one[1000005],c[1000005];

int 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)]);
    }
}
int main(){
	scanf("%d%d%I64d",&n,&d,&x);
	initAB();
	for (int i=0;i<n;i++){
		if (b[i]==1) one[++nn]=i;
		maxv[++mn]=i;int td=mn;
		while (td>1&&a[maxv[td-1]]<a[maxv[td]]){
			swap(maxv[td-1],maxv[td]);td--;
		}
		if (mn==501) mn--;
		if (nn<=500){
			for (int j=1;j<=nn;j++)
				c[i]=max(c[i],a[i-one[j]]);
		}
		else{
			for (int j=1;j<=mn;j++)
				if (b[i-maxv[j]]==1){
					c[i]=a[maxv[j]];break;
				}
		}
	}
	for (int i=0;i<n;i++) printf("%d\n",c[i]);
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
long long x;
int n,d,a[100005],b[100005],i,ans[100005],o,Q[100005],j;
struct node {int x,y;} t[100005];
int work(){x=(x*37+10007)%1000000007; return x;}
int cmp(node i,node j) {return i.y>j.y;}
int main()
{
    cin>>n>>d>>x;
    for (i=0; i<n; i++) a[i]=i+1;
    for (i=0; i<n; i++) swap(a[i],a[work()%(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[work()%(i+1)]);
    for (i=0; i<n; i++)
    {
        t[i].x=i;
        t[i].y=a[i];
    }
    sort(t,t+n,cmp);
    for (i=0; i<min(500,n); i++)
        for (j=0; j<n; j++) if (b[j] && t[i].x+j<n && !ans[j+t[i].x]) ans[j+t[i].x]=t[i].y;
    for (i=0; i<n; i++) if (b[i]) Q[++o]=i;
    for (i=0; i<n; i++) if (!ans[i]) for (j=1; j<=o; j++) if (Q[j]<=i) ans[i]=max(ans[i],a[i-Q[j]]);
    for (i=0; i<n; i++) printf("%d\n",ans[i]);
    return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <complex>
#include <string>
#include <cstring>
#include <vector>
#include <map>
using namespace std;
long long x;
int a[200005],b[200005],n,d,i,j,o,O,T[200005],p[200005],ans[200005];
struct node {int x,y;} t[200005];
long long get()
{
    x=(x*37+10007)%1000000007;
    return x;
}
int cmp(node i,node j) {return i.x>j.x;}
int main()
{
    cin>>n>>d>>x;
    for (i=0; i<n; i++) a[i]=i+1;
    for (i=0; i<n; i++) swap(a[i],a[get()%(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[get()%(i+1)]);
    for (i=0; i<n; i++) if (b[i]==1) p[++o]=i;
    if (d<=1000)
    {

        for (i=0; i<n; i++)
          for (j=1; j<=o; j++)
            ans[i+p[j]]=max(ans[i+p[j]],a[i]);
        for (i=0; i<n; i++) printf("%d\n",ans[i]);
        return 0;
    }
    for (i=0; i<n; i++) {t[i].x=a[i]; t[i].y=i;}
    sort(t,t+n,cmp);
    for (i=1; i<=1000; i++)
    {
        for (j=1; j<=o; j++) if (!ans[t[i].y+p[j]]) ans[t[i].y+p[j]]=t[i].x;
    }
    for (i=0; i<n; i++) if (!ans[i]) T[++O]=i;
    for (i=1; i<=O; i++)
      for (j=1; j<=o; j++)
        if (T[i]-p[j]>=0) ans[i]=max(ans[i],a[T[i]-p[j]]);
    for (i=0; i<n; i++) printf("%d\n",ans[i]);
    return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <complex>
#include <string>
#include <cstring>
#include <vector>
#include <map>
using namespace std;
long long x;
int a[200005],b[200005],n,d,i,j,o,O,T[200005],p[200005],ans[200005];
struct node {int x,y;} t[200005];
long long get()
{
    x=(x*37+10007)%1000000007;
    return x;
}
int cmp(node i,node j) {return i.x>j.x;}
int main()
{
    cin>>n>>d>>x;
    for (i=0; i<n; i++) a[i]=i+1;
    for (i=0; i<n; i++) swap(a[i],a[get()%(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[get()%(i+1)]);
    for (i=0; i<n; i++) if (b[i]==1) p[++o]=i;
    if (d<=1000)
    {

        for (i=0; i<n; i++)
          for (j=1; j<=o; j++)
            ans[i+p[j]]=max(ans[i+p[j]],a[i]);
        for (i=0; i<n; i++) printf("%d\n",ans[i]);
        return 0;
    }
    for (i=0; i<n; i++) {t[i].x=a[i]; t[i].y=i;}
    sort(t,t+n,cmp);
    for (i=1; i<=n; i++) t[i]=t[i-1];
    for (i=1; i<=1000; i++)
    {
        for (j=1; j<=o; j++) if (!ans[t[i].y+p[j]]) ans[t[i].y+p[j]]=t[i].x;
    }
    for (i=0; i<n; i++) if (!ans[i]) T[++O]=i;
    for (i=1; i<=O; i++)
      for (j=1; j<=o; j++)
        if (T[i]-p[j]>=0) ans[T[i]]=max(ans[T[i]],a[T[i]-p[j]]);
    for (i=0; i<n; i++) printf("%d\n",ans[i]);
    return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <complex>
#include <string>
#include <cstring>
#include <vector>
#include <map>
using namespace std;
long long x;
int a[200005],b[200005],n,d,i,j,o,O,T[200005],p[200005],ans[200005];
struct node {int x,y;} t[200005];
long long get()
{
    x=(x*37+10007)%1000000007;
    return x;
}
int cmp(node i,node j) {return i.x>j.x;}
int main()
{
    cin>>n>>d>>x;
    for (i=0; i<n; i++) a[i]=i+1;
    for (i=0; i<n; i++) swap(a[i],a[get()%(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[get()%(i+1)]);
    for (i=0; i<n; i++) if (b[i]==1) p[++o]=i;
    if (d<=1000)
    {

        for (i=0; i<n; i++)
          for (j=1; j<=o; j++)
            ans[i+p[j]]=max(ans[i+p[j]],a[i]);
        for (i=0; i<n; i++) printf("%d\n",ans[i]);
        return 0;
    }
    for (i=0; i<n; i++) {t[i].x=a[i]; t[i].y=i;}
    sort(t,t+n,cmp);
    for (i=1; i<=1000; i++)
    {
        for (j=1; j<=o; j++) if (!ans[t[i].y+p[j]]) ans[t[i].y+p[j]]=t[i].x;
    }
    for (i=0; i<n; i++) if (!ans[i]) T[++O]=i;
    for (i=1; i<=O; i++)
      for (j=1; j<=o; j++)
        if (T[i]-p[j]>=0) ans[T[i]]=max(ans[T[i]],a[T[i]-p[j]]);
    for (i=0; i<n; i++) printf("%d\n",ans[i]);
    return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
long long x;
int n,d,a[100005],b[100005],i,ans[100005],o,Q[100005],j;
struct node {int x,y;} t[100005];
int work(){x=(x*37+10007)%1000000007; return x;}
int cmp(node i,node j) {return i.y>j.y;}
int main()
{
    cin>>n>>d>>x;
    for (i=0; i<n; i++) a[i]=i+1;
    for (i=0; i<n; i++) swap(a[i],a[work()%(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[work()%(i+1)]);
    for (i=0; i<n; i++)
    {
        t[i].x=i;
        t[i].y=a[i];
    }
    sort(t,t+n,cmp);
    for (i=0; i<min(500,n); i++)
        for (j=0; j<n; j++) if (b[j] && t[i].x+j<n && !ans[j+t[i].x]) ans[j+t[i].x]=t[i].y;
    for (i=0; i<n; i++) if (b[i]) Q[++o]=b[i];
    for (i=0; i<n; i++) if (!ans[i]) for (j=1; j<=o; j++) if (Q[j]<=i) ans[i]=max(ans[i],a[i-Q[j]]);
    for (i=0; i<n; i++) printf("%d\n",ans[i]);
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

#define MAXN 100005
#define ll long long

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

ll get_next_x();
void build_a();
void build_b();

int main()
{
	int i,j,k;
	cin>>n>>d>>x;
	build_a();
	if (d>=n)
	{
		c[0]=a[0];
		for (i=1;i<n;i++)
		{
			c[i]=max(c[i-1],a[i]);
		}
	}
	else
	{
		build_b();
		memset(c,-1,sizeof(c));
		for (i=0;i<n;i++)
		{
			if (b[i]==0) continue;
			for (j=0;j<n;j++)
			{
				if (i+j>=n) continue;
				c[i+j]=max(a[j],c[i+j]);
			}
		}
	}
	for (i=0;i<n;i++)
	{
		cout<<c[i]<<endl;
	}
	return 0;
}

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

void build_a()
{
	int i,x,y,temp;
	for (i=0;i<n;i++)
	{
		a[i]=i+1;
	}
	for (i=0;i<n;i++)
	{
		x=i; y=get_next_x()%(i+1);
		temp=a[x];
		a[x]=a[y];
		a[y]=temp;
	}
}

void build_b()
{
	int i,x,y,temp;
	for (i=0;i<n;i++)
	{
		if (i<d) b[i]=1;
		else b[i]=0;
	}
	for (i=0;i<n;i++)
	{
		x=i; y=get_next_x()%(i+1);
		temp=b[x];
		b[x]=b[y];
		b[y]=temp;
	}
}


#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

#define MAXN 100005
#define ll long long

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

ll get_next_x();
void build_a();
void build_b();

int main()
{
	int i,j,k;
	cin>>n>>d>>x;
	build_a();
	if (d>=n)
	{
		c[0]=a[0];
		for (i=1;i<n;i++)
		{
			c[i]=max(c[i-1],a[i]);
		}
	}
	else
	{
		build_b();
		memset(c,0,sizeof(c));
		for (i=0;i<n;i++)
		{
			if (b[i]==0) continue;
			for (j=0;j<n;j++)
			{
				if (i+j>=n) continue;
				c[i+j]=max(a[j],c[i+j]);
			}
		}
	}
	for (i=0;i<n;i++)
	{
		cout<<c[i]<<endl;
	}
	return 0;
}

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

void build_a()
{
	int i,x,y,temp;
	for (i=0;i<n;i++)
	{
		a[i]=i+1;
	}
	for (i=0;i<n;i++)
	{
		x=i; y=get_next_x()%(i+1);
		temp=a[x];
		a[x]=a[y];
		a[y]=temp;
	}
}

void build_b()
{
	int i,x,y,temp;
	for (i=0;i<n;i++)
	{
		if (i<d) b[i]=1;
		else b[i]=0;
	}
	for (i=0;i<n;i++)
	{
		x=i; y=get_next_x()%(i+1);
		temp=b[x];
		b[x]=b[y];
		b[y]=temp;
	}
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

#define MAXN 100005
#define ll long long

struct node
{
	ll pre,next,val;
};

ll n,d,x;
ll a[MAXN],b[MAXN],c[MAXN];
node li[MAXN];

ll getNextX();
void initAB();

int main()
{
	ll i,j,k,len;
	cin>>n>>d>>x;
	ll sq;
	initAB();
	memset(c,0,sizeof(c));
	sq=(ll)sqrt(n);
	for (i=0;i<=n;i++)
	{
		li[i].val=i-1;
		li[i].pre=i-1;
		li[i].next=i+1;
	}
	if (d<=sq)
	{
		vector <ll> pos;
		len=0;
		for (i=0;i<n;i++)
		{
			if (b[i]==1)
			{
				pos.push_back(i);
				len++;
			}
		}
		for (i=0;i<n;i++)
		{
			for (j=0;j<len;j++)
			{
				if (i+pos[j]>=n) continue;
				c[i+pos[j]]=max(c[i+pos[j]],a[i]);
			}
		}
		for (i=0;i<n;i++)
		{
			cout<<c[i]<<endl;
		}
	}
	else
	{
		ll hs[MAXN];
		for (i=0;i<n;i++)
		{
			hs[a[i]]=i;
		}
		for (i=n;i>=1;i--)
		{
			ll y=hs[i];
			for (j=0;j!=n+1;j=li[j].next)
			{
				if (li[j].val==-1) continue;

				ll z=li[j].val;
				if (z-y<0) continue;
				if (b[z-y]==1)
				{
					c[z]=i;
					li[li[j].pre].next=li[j].next;
					li[li[j].next].pre=li[j].pre;
				}
			}
		}
		for (i=0;i<n;i++)
		{
			cout<<c[i]<<endl;
		}
	}
	return 0;
}

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

void initAB()
{
	ll 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)]);
    }
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#define LL long long
using namespace std;
LL x;
LL getnext(){
	x = (x*37+10007)%1000000007;
	return x;
}
int a[100005];
int b[100005];
int inde[100005];
int ans[100005];
bool cmp (int x,int y)
{
	return (a[x]>a[y]);
}
int main ()
{
	int n,d;
	scanf("%d%d%I64d",&n,&d,&x);
	for(int i=0;i<n;i++){
		a[i] = i+1;
	}
	for(int i=0;i<n;i++){
		swap(a[i],a[getnext()%(i+1)]);
	}
	for(int i=0;i<n;i++){
		if(i<d)
			b[i] = 1;
		else
			b[i] = 0;
	}
	for(int i=0;i<n;i++){
		swap(b[i],b[getnext()%(i+1)]);
	}
	for(int i=0;i<n;i++){
		inde[i]  = i;
	}
	bool yes;
	sort(inde,inde+n,cmp);
	for(int i=0;i<n;i++){
		yes = false;
		for(int j=0;j<n;j++){
			int tmp = i-inde[j];
			if(tmp<0) continue;
			if(b[tmp]){
				printf("%d\n",a[inde[j]]);
				yes = true;
				break;
			}
		}
		if(!yes) printf("0\n");
	}
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#define LL long long
using namespace std;
LL x;
LL getnext(){
	x = (x*37+10007)%1000000007;
	return x;
}
int a[100005];
int b[100005];
int inde[100005];
int ans[100005];
bool cmp (int x,int y)
{
	return (a[x]>a[y]);
}
int main ()
{
	int n,d;
	scanf("%d%d%I64d",&n,&d,&x);
	for(int i=0;i<n;i++){
		a[i] = i+1;
	}
	for(int i=0;i<n;i++){
		swap(a[i],a[getnext()%(i+1)]);
	}
	for(int i=0;i<n;i++){
		if(i<d)
			b[i] = 1;
		else
			b[i] = 0;
	}
	for(int i=0;i<n;i++){
		swap(b[i],b[getnext()%(i+1)]);
	}
	/*for(int i=0;i<n;i++){
		printf("%d ",a[i]);
	}
	printf("\n");
	for(int i=0;i<n;i++){
		printf("%d ",b[i]);
	}
	printf("\n");*/
	for(int i=0;i<n;i++){
		inde[i]  = i;
	}
	sort(inde,inde+n,cmp);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			int tmp = i-inde[j];
			if(tmp<0) continue;
			if(b[tmp]){
				printf("%d\n",a[inde[j]]);
				break;
			}
		}
	}
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
struct ed
{
	int v,next;
};
int head[100005];
ed edge[200005];
int is[100005];
int a[100005];
int M,cnt=0;
void addedge(int u,int v)
{
	edge[M].v = v;
	edge[M].next = head[u];
	head[u] = M++;
}
void dfs(int u,int t,int s,int f)
{

	int st = (t&s)?1:0;
	//printf("%d %d %d %d %d\n",u,t,s,a[u],st);
	is[u] = (st==a[u])?0:1;
	if(is[u]){
		st  = t^s;
		cnt++;
	}
	else
		st = t;
	for(int i =head[u];i;i=edge[i].next){
		int v = edge[i].v;
		if(v==f) continue;
		dfs(v,st,3-s,u);
	}
}
int main ()
{
	int n,u,v;
	M =1;
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		addedge(u,v);
		addedge(v,u);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&v);
		a[i]^=v;
	}
	dfs(1,0,1,0);
	printf("%d\n",cnt);
	for(int i=1;i<=n;i++){
		if(is[i]) printf("%d\n",i);
	}
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#define LL long long
using namespace std;
LL x;
LL getnext(){
	x = (x*37+10007)%1000000007;
	return x;
}
int a[100005];
int b[100005];
int inde[100005];
int ans[100005];
bool cmp (int x,int y)
{
	return (a[x]>a[y]);
}
int main ()
{
	int n,d;
	scanf("%d%d%I64d",&n,&d,&x);
	for(int i=0;i<n;i++){
		a[i] = i+1;
	}
	for(int i=0;i<n;i++){
		swap(a[i],a[getnext()%(i+1)]);
	}
	for(int i=0;i<n;i++){
		if(i<d)
			b[i] = 1;
		else
			b[i] = 0;
	}
	for(int i=0;i<n;i++){
		swap(b[i],b[getnext()%(i+1)]);
	}
    if(d<1000){
        int cnt =0;
        for(int i=0;i<n;i++){
            if(!b[i]) continue;
            for(int j=0;j<n;j++){
                ans[i+j] = max(ans[i+j],a[j]);
            }
        }
        for(int i=0;i<n;i++){
            printf("%d\n",ans[i]);
        }
        return 0;
    }
	for(int i=0;i<n;i++){
		inde[i]  = i;
	}
	bool yes;
	sort(inde,inde+n,cmp);
	for(int i=0;i<n;i++){
		yes = false;
		for(int j=0;j<n;j++){
			int tmp = i-inde[j];
			if(tmp<0) continue;
			if(b[tmp]){
				printf("%d\n",a[inde[j]]);
				yes = true;
				break;
			}
		}
		if(!yes) printf("0\n");
	}
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#define LL long long
using namespace std;
LL x;
LL getnext(){
	x = (x*37+10007)%1000000007;
	return x;
}
int a[100];
int b[100];
int inde[100];
int ans[100];
bool cmp (int x,int y)
{
	return (a[x]>a[y]);
}
int main ()
{
	int n,d;
	scanf("%d%d%I64d",&n,&d,&x);
	for(int i=0;i<n;i++){
		a[i] = i+1;
	}
	for(int i=0;i<n;i++){
		swap(a[i],a[getnext()%(i+1)]);
	}
	for(int i=0;i<n;i++){
		if(i<d)
			b[i] = 1;
		else
			b[i] = 0;
	}
	for(int i=0;i<n;i++){
		swap(b[i],b[getnext()%(i+1)]);
	}
	/*for(int i=0;i<n;i++){
		printf("%d ",a[i]);
	}
	printf("\n");
	for(int i=0;i<n;i++){
		printf("%d ",b[i]);
	}
	printf("\n");*/
	for(int i=0;i<n;i++){
		inde[i]  = i;
	}
	sort(inde,inde+n,cmp);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			int tmp = i-inde[j];
			if(tmp<0) continue;
			if(b[tmp]){
				printf("%d\n",a[inde[j]]);
				break;
			}
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

using namespace std;

ifstream fin ("C.in");

int n,d,x,a[100010],b[100010],next[100010],c[100010];

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

void solve ()
{
    int last = -1,first = -1;
    for (int i=0; i<n; ++i)
    {
        if (b[i] == 1)
        {
            if (first == -1)
              first = i;

            if (last != -1)
              next[last] = i;
            last = i;
        }
    }
    next[last] = n;

    int sq = n-sqrt (n);

    for (int i=0; i<n; ++i)
    {
        if (a[i] > sq)
        {
            for (int j=first; i+j<n; j = next[j])
              c[i+j] = max (c[i+j],a[i]);
        }
    }

    for (int i=0; i<n; ++i)
    {
        if (!c[i])
        {
            for (int j=first; i-j>=0; j = next[j])
             c[i] = max (c[i],a[i-j]);
        }
    }

   /* for (int i=0; i<n; ++i)
      cout<<c[i]<<"\n";*/
}

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)]);
    }
}

int main()
{
    cin>>n>>d>>x;
    initAB ();
    solve ();
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

using namespace std;

ifstream fin ("C.in");

int n,d,x,a[100010],b[100010],next[100010],c[100010];

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

void solve ()
{
    int last = -1,first = -1;
    for (int i=0; i<n; ++i)
    {
        if (b[i] == 1)
        {
            if (first == -1)
              first = i;

            if (last != -1)
              next[last] = i;
            last = i;
        }
    }
    next[last] = n;

    int sq = n-sqrt (n);

    for (int i=0; i<n; ++i)
    {
        if (a[i] > sq)
        {
            for (int j=first; i+j<n; j = next[j])
              c[i+j] = max (c[i+j],a[i]);
        }
    }

    for (int i=0; i<n; ++i)
    {
        if (!c[i])
        {
            for (int j=first; i-j>=0; j = next[j])
             c[i] = max (c[i],a[i-j]);
        }
    }

    for (int i=0; i<n; ++i)
      cout<<c[i]<<"\n";
}

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)]);
    }
}

int main()
{
    fin>>n>>d>>x;
    initAB ();
    solve ();
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

using namespace std;

ifstream fin ("C.in");

int n,d,x,a[100010],b[100010],next[100010],c[100010];

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

void solve ()
{
    int last = -1,first = -1;
    for (int i=0; i<n; ++i)
    {
        if (b[i] == 1)
        {
            if (first == -1)
              first = i;

            if (last != -1)
              next[last] = i;
            last = i;
        }
    }
    next[last] = n;

    int sq = sqrt (n);

    for (int i=0; i<n; ++i)
    {
        if (a[i] > sq)
        {
            for (int j=first; i+j<n; j = next[j])
              c[i+j] = max (c[i+j],a[i]);
        }
    }

    for (int i=0; i<n; ++i)
    {
        if (!c[i])
        {
            for (int j=first; i-j>=0; j = next[j])
             c[i] = max (c[i],a[i-j]);
        }
    }

    for (int i=0; i<n; ++i)
      cout<<c[i]<<"\n";
}

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)]);
    }
}

int main()
{
    cin>>n>>d>>x;
    initAB ();
    solve ();
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

using namespace std;

ifstream fin ("C.in");

int n,d,x,a[100010],b[100010],next[100010],c[100010];

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

void solve ()
{
    int last = -1,first = -1;
    for (int i=0; i<n; ++i)
    {
        if (b[i] == 1)
        {
            if (first == -1)
              first = i;

            if (last != -1)
              next[last] = i;
            last = i;
        }
    }
    next[last] = n;

    int sq = n-sqrt (n);

    for (int i=0; i<n; ++i)
    {
        if (a[i] > sq)
        {
            for (int j=first; i+j<n; j = next[j])
              c[i+j] = max (c[i+j],a[i]);
        }
    }

    for (int i=0; i<n; ++i)
    {
        if (!c[i])
        {
            for (int j=first; i-j>=0; j = next[j])
             c[i] = max (c[i],a[i-j]);
        }
    }

    for (int i=0; i<n; ++i)
      cout<<c[i]<<"\n";
}

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)]);
    }
}

int main()
{
    cin>>n>>d>>x;
    initAB ();
    solve ();
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

using namespace std;

ifstream fin ("C.in");

int n,d,x,a[100010],b[100010],next[100010],c[100010];

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

void solve ()
{
    int last = -1,first = -1;
    for (int i=0; i<n; ++i)
    {
        if (b[i] == 1)
        {
            if (first == -1)
              first = i;

            if (last != -1)
              next[last] = i;
            last = i;
        }
    }
    next[last] = n;

    int sq = sqrt (n);

    for (int i=0; i<n; ++i)
    {
        if (a[i] > sq)
        {
            for (int j=first; j<n; j = next[j])
              c[i+j] = max (c[i+j],a[i]);
        }
    }

    for (int i=0; i<n; ++i)
    {
        if (!c[i])
        {
            for (int j=first; j<n; j = next[j])
             c[i] = max (c[i],a[i-j]);
        }
    }

    for (int i=0; i<n; ++i)
      cout<<c[i]<<"\n";
}

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)]);
    }
}

int main()
{
    cin>>n>>d>>x;
    initAB ();
    solve ();
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

using namespace std;

ifstream fin ("C.in");

int n,d,x,a[100010],b[100010],next[100010],c[100010];

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

void solve ()
{
    int last = -1,first = -1;
    for (int i=0; i<n; ++i)
    {
        if (b[i] == 1)
        {
            if (first == -1)
              first = i;

            if (last != -1)
              next[last] = i;
            last = i;
        }
    }
    next[last] = n;

    int sq = sqrt (n);

    for (int i=0; i<n; ++i)
    {
        if (a[i] > sq)
        {
            for (int j=first; j<n; j = next[j])
              c[i+j] = max (c[i+j],a[i]);
        }
    }

    for (int i=0; i<n; ++i)
    {
        if (!c[i])
        {
            for (int j=first; j<n; j = next[j])
             c[i] = max (c[i],a[i-j]);
        }
    }

    for (int i=0; i<n; ++i)
      cout<<c[i]<<"\n";
}

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)]);
    }
}

int main()
{
    fin>>n>>d>>x;
    initAB ();
    solve ();
}


#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 100010;
struct node
{
    int x,y;
    node(){}
    node(int u,int v)
    {
        x=u,y=v;
    }
}a[maxn];
ll xx;
int n,d,b[maxn];
int pre[maxn],next[maxn];
int pp[maxn],nn[maxn];
int del[maxn],cnt[maxn];
bool cmp(const node &a,const node &b)
{
    return a.y>b.y;
}
ll getNextX() {
    xx = (xx * 37LL + 10007LL) % 1000000007LL;
    return xx;
}
void initAB() {
    int i,j;
    for(i = 0; i < n; i = i + 1){
        a[i].y = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i].y, a[(int)getNextX() % (i + 1)].y);
    }
    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[(int)getNextX() % (i + 1)]);
    }
    for (i=n-1;i>=0;i--)
    {
        a[i].x=i;
    }
}
int dfs(int x)
{
//    printf("x==%d \n",x);
    if (!del[x])
        return x;
    if (nn[x]==-1)
        return -1;
    return nn[x]=dfs(nn[x]);
}
int main()
{
    while (~scanf("%d%d%I64d",&n,&d,&xx))
    {
        ll cc=xx;
        int i,j,now,r;
        initAB();
        int x=-1;
//        for (i=0;i<n;i++)
//        {
//            printf("%d ",b[i]);
//        }
//        puts("");
        sort(a,a+n,cmp);
        for (i=n-1;i>=0;i--)
        {
            next[i]=x;
            nn[i]=i+1;
            pp[i]=i-1;
            if (b[i])x=i;
            del[i]=0;
            cnt[i]=0;
        }
        nn[n-1]=-1;
        for (i=0;i<n;i++)
        {
            r=n-a[i].x;
            now=0;
            int cx,dx;
            if (b[now])
                cx=now;
            else
                cx=next[now];
            dx=cx+a[i].x;
            dx=dfs(dx);
//            printf("rr=%d %d\n",rr,pred);
//            if (dx==-1)
//                continue;
            while (cx<r&&dx<n&&cx!=-1&&dx!=-1)
            {
//                printf("cx==%d dx==%d del=%d\n",cx,dx,del[dx]);
//                system("pause");
                if (cx+a[i].x<dx)
                {
                    x=dx-a[i].x;
                    if (b[x])
                        cx=x;
                    else
                        cx=next[x];
                }
                if (a[i].x+cx>dx)
                {
                    x=a[i].x+cx;
                    if (!del[x])
                        dx=x;
                    else
                        dx=nn[x];
                }
                if (del[dx])
                {
                    dx=nn[dx];
                }
                if (dx!=-1&&cx!=-1&&a[i].x+cx==dx&&!del[dx])
                {
                    del[dx]=1;
                    cnt[dx]=a[i].y;
                    int xx=dx;
                    nn[pp[dx]]=nn[dx];
                    pp[nn[dx]]=pp[dx];
                    cx=next[cx];
                    dx=nn[xx];
                }
            }
        }
        for (i=0;i<n;i++)
        {
            if (cnt[i])
                printf("%d\n",cnt[i]);
            else
                puts("0");
        }
//        puts("****");
    }
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 100010;
struct node
{
    int x,y;
    node(){}
    node(int u,int v)
    {
        x=u,y=v;
    }
}a[maxn];
ll xx;
int n,d,b[maxn];
int pre[maxn],next[maxn];
int pp[maxn],nn[maxn];
int del[maxn],cnt[maxn];
bool cmp(const node &a,const node &b)
{
    return a.y>b.y;
}
ll getNextX() {
    xx = (xx * 37LL + 10007LL) % 1000000007LL;
    return xx;
}
void initAB() {
    int i,j;
    for(i = 0; i < n; i = i + 1){
        a[i].y = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i].y, a[(int)getNextX() % (i + 1)].y);
    }
    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[(int)getNextX() % (i + 1)]);
    }
    for (i=n-1;i>=0;i--)
    {
        a[i].x=i;
    }
}
int dfs(int x)
{
//    printf("x==%d \n",x);
    if (!del[x])
        return x;
    if (nn[x]==-1)
        return -1;
    return nn[x]=dfs(nn[x]);
}
void put(int x)
{
    char s[10];
    int len=0;
    do {
        s[len++]=x%10+'0';
        x/=10;
    }while(x);
    for (int i=len-1;i>=0;i--)
    {
        putchar(s[i]);
    }
    puts("");
}
int main()
{
    while (scanf("%d%d%I64d",&n,&d,&xx)!=EOF)
    {
        int i,j,now,r;
        initAB();
        int x=-1;
//        for (i=0;i<n;i++)
//        {
//            printf("%d ",b[i]);
//        }
//        puts("");
        sort(a,a+n,cmp);
        for (i=n-1;i>=0;i--)
        {
            next[i]=x;
            nn[i]=i+1;
            pp[i]=i-1;
            if (b[i])x=i;
            del[i]=0;
            cnt[i]=0;
        }
        nn[n-1]=-1;
        for (i=0;i<n;i++)
        {
            r=n-a[i].x;
            now=0;
            int cx,dx;
            if (b[now])
                cx=now;
            else
                cx=next[now];
            dx=cx+a[i].x;
            dx=dfs(dx);
//            for (j=0;j<n;j++)
//            {
//                printf("%d ",nn[j]);
//            }
//            printf("dddd===%d\n",dx);
            while (cx<r&&dx<n&&cx!=-1&&dx!=-1)
            {
//                printf("cx==%d dx==%d del=%d\n",cx,dx,del[dx]);
//                system("pause");
                if (cx+a[i].x<dx)
                    cx=next[cx];
                if (a[i].x+cx>dx||del[dx])
                    dx=nn[dx];
                if (a[i].x+cx==dx&&!del[dx])
                {
                    del[dx]=1;
                    cnt[dx]=a[i].y;
                    int xx=dx;
                    nn[pp[dx]]=nn[dx];
                    pp[nn[dx]]=pp[dx];
                    cx=next[cx];
                    dx=nn[xx];
                }
            }
        }
        for (i=0;i<n;i++)
        {
            if (cnt[i])
            put(cnt[i]);
            else
                puts("0");
        }
    }
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll maxn = 100010;
struct node
{
    ll x,y;
    node(){}
    node(ll u,ll v)
    {
        x=u,y=v;
    }
}a[maxn];
ll n,d,x,b[maxn];
ll pre[maxn],next[maxn];
ll pp[maxn],nn[maxn];
ll del[maxn],cnt[maxn];
bool cmp(const node &a,const node &b)
{
    return a.y>b.y;
}
ll getNextX() {
    x = (x * 37 + 10007) % 1000000007;
    return x;
}
void initAB() {
    ll i,j;
    for(i = 0; i < n; i = i + 1){
        a[i].y = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i].y, a[getNextX() % (i + 1)].y);
    }
    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=n-1;i>=0;i--)
    {
        a[i].x=i;
    }
}
ll dfs(ll x)
{
//    printf("x==%I64d \n",x);
    if (!del[x])
        return x;
    if (nn[x]==-1)
        return -1;
    nn[x]=dfs(nn[x]);
}
int main()
{
    while (scanf("%I64d%I64d%I64d",&n,&d,&x)!=EOF)
    {
        ll i,j,now,r;
        initAB();
        x=-1;
        sort(a,a+n,cmp);
        for (i=n-1;i>=0;i--)
        {
            next[i]=x;
            nn[i]=i+1;
            pp[i]=i-1;
            if (b[i])x=i;
            del[i]=0;
            cnt[i]=0;
        }
        nn[n-1]=-1;
        for (i=0;i<n;i++)
        {
            r=n-a[i].x;
            now=0;
            ll cx,dx;
            if (b[now])
                cx=now;
            else
                cx=next[now];
            dx=cx+a[i].x;
            dx=dfs(dx);
            while (cx<r&&dx<n&&cx!=-1&&dx!=-1)
            {
//                printf("cx==%I64d dx==%I64d del=%I64d\n",cx,dx,del[dx]);
//                system("pause");
                if (cx+a[i].x<dx)
                    cx=next[cx];
                if (a[i].x+cx>dx)
                    dx=nn[dx];
                if (a[i].x+cx==dx)
                {
                    del[dx]=1;
                    cnt[dx]=a[i].y;
                    ll xx=dx;
                    nn[pp[dx]]=nn[dx];
                    pp[nn[dx]]=pp[dx];
                    cx=next[cx];
                    dx=nn[xx];
                }
            }
        }
        for (i=0;i<n;i++)
        {
            printf("%I64d\n",cnt[i]);
        }
    }
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 100010;
struct node
{
    int x,y;
    node(){}
    node(int u,int v)
    {
        x=u,y=v;
    }
}a[maxn];
ll xx;
int n,d,b[maxn];
int pre[maxn],next[maxn];
int pp[maxn],nn[maxn];
int del[maxn],cnt[maxn];
bool cmp(const node &a,const node &b)
{
    return a.y>b.y;
}
ll getNextX() {
    xx = (xx * 37LL + 10007LL) % 1000000007LL;
    return xx;
}
void initAB() {
    int i,j;
    for(i = 0; i < n; i = i + 1){
        a[i].y = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i].y, a[(int)getNextX() % (i + 1)].y);
    }
    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[(int)getNextX() % (i + 1)]);
    }
    for (i=n-1;i>=0;i--)
    {
        a[i].x=i;
    }
}
int dfs(int x)
{
//    printf("x==%d \n",x);
    if (!del[x])
        return x;
    if (nn[x]==-1)
        return -1;
    return nn[x]=dfs(nn[x]);
}
int main()
{
    scanf("%d%d%I64d",&n,&d,&xx);
    {
        ll cc=xx;
        int i,j,now,r;
        initAB();
        int x=-1;
//        for (i=0;i<n;i++)
//        {
//            printf("%d ",b[i]);
//        }
//        puts("");
        sort(a,a+n,cmp);
        for (i=n-1;i>=0;i--)
        {
            next[i]=x;
            nn[i]=i+1;
            pp[i]=i-1;
            if (b[i])x=i;
            del[i]=0;
            cnt[i]=0;
        }
        nn[n-1]=-1;
        for (i=0;i<n;i++)
        {
            r=n-a[i].x;
            now=0;
            int cx,dx;
            if (b[now])
                cx=now;
            else
                cx=next[now];
            dx=cx+a[i].x;
            dx=dfs(dx);
//            printf("rr=%d %d\n",rr,pred);
//            if (dx==-1)
//                continue;
            while (cx<r&&dx<n&&cx!=-1&&dx!=-1)
            {
//                printf("cx==%d dx==%d del=%d\n",cx,dx,del[dx]);
//                system("pause");
                if (cx+a[i].x<dx)
                {
                    x=dx-a[i].x;
                    if (b[x])
                        cx=x;
                    else
                        cx=next[x];
                }
                if (cx==-1||cx>=r)
                    break;
                if (a[i].x+cx>dx)
                {
                    x=a[i].x+cx;
                    if (!del[x])
                        dx=x;
                    else
                        dx=nn[x];
                }
                if (dx>=n||dx==-1)
                    break;
                if (del[dx])
                {
                    dx=dfs(dx);
                }
                if (dx>=n||dx==-1)
                    break;
                if (a[i].x+cx==dx&&!del[dx])
                {
                    del[dx]=1;
                    cnt[dx]=a[i].y;
                    int xx=dx;
                    nn[pp[dx]]=nn[dx];
                    pp[nn[dx]]=pp[dx];
                    cx=next[cx];
                    dx=nn[xx];
                }
            }
        }
        for (i=0;i<n;i++)
        {
            if (cnt[i])
                printf("%d\n",cnt[i]);
            else
                puts("0");
        }
//        puts("****");
    }
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 100010;
struct node
{
    int x,y;
    node(){}
    node(int u,int v)
    {
        x=u,y=v;
    }
}a[maxn];
ll xx;
int n,d,b[maxn];
int pre[maxn],next[maxn];
int pp[maxn],nn[maxn];
int del[maxn],cnt[maxn];
bool cmp(const node &a,const node &b)
{
    return a.y>b.y;
}
ll getNextX() {
    xx = (xx * 37LL + 10007LL) % 1000000007LL;
    return xx;
}
void initAB() {
    int i,j;
    for(i = 0; i < n; i = i + 1){
        a[i].y = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i].y, a[(int)getNextX() % (i + 1)].y);
    }
    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[(int)getNextX() % (i + 1)]);
    }
    for (i=n-1;i>=0;i--)
    {
        a[i].x=i;
    }
}
int dfs(int x)
{
//    printf("x==%d \n",x);
    if (!del[x])
        return x;
    if (nn[x]==-1)
        return -1;
    return nn[x]=dfs(nn[x]);
}
int main()
{
    scanf("%d%d%I64d",&n,&d,&xx);
    {
        ll cc=xx;
        int i,j,now,r,rr=n-1;
        initAB();
        int x=-1;
//        for (i=0;i<n;i++)
//        {
//            printf("%d ",b[i]);
//        }
//        puts("");
        sort(a,a+n,cmp);
        for (i=n-1;i>=0;i--)
        {
            next[i]=x;
            nn[i]=i+1;
            pp[i]=i-1;
            if (b[i])x=i;
            del[i]=0;
            cnt[i]=0;
        }
        nn[n-1]=-1;
        for (i=0;i<n;i++)
        {
            r=n-a[i].x;
            now=0;
            int cx,dx;
            if (b[now])
                cx=now;
            else
                cx=next[now];
            dx=cx+a[i].x;
            dx=dfs(dx);
            int pred=dx;
            int flag=0;
            while (cx<r&&dx<=rr&&cx!=-1&&dx!=-1)
            {
//                printf("cx==%d dx==%d del=%d\n",cx,dx,del[dx]);
//                system("pause");
                if (cx+a[i].x<dx)
                    cx=next[cx];
                if (a[i].x+cx>dx||del[dx])
                    dx=nn[dx];
                if (a[i].x+cx==dx&&!del[dx])
                {
                    del[dx]=1;
                    cnt[dx]=a[i].y;
                    int xx=dx;
                    nn[pp[dx]]=nn[dx];
                    pp[nn[dx]]=pp[dx];
                    cx=next[cx];
                    dx=nn[xx];
                    flag=1;
                }
            }
            if (!flag)
                rr=min(rr,pred);
        }
        for (i=0;i<n;i++)
        {
            if (cnt[i])
                printf("%d\n",cnt[i]);
            else
                puts("0");
        }
    }
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 100010;
struct node
{
    int x,y;
    node(){}
    node(int u,int v)
    {
        x=u,y=v;
    }
}a[maxn];
ll xx;
int n,d,b[maxn];
int pre[maxn],next[maxn];
int pp[maxn],nn[maxn];
int del[maxn],cnt[maxn];
bool cmp(const node &a,const node &b)
{
    return a.y>b.y;
}
ll getNextX() {
    xx = (xx * 37LL + 10007LL) % 1000000007LL;
    return xx;
}
void initAB() {
    int i,j;
    for(i = 0; i < n; i = i + 1){
        a[i].y = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i].y, a[(int)getNextX() % (i + 1)].y);
    }
    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[(int)getNextX() % (i + 1)]);
    }
    for (i=n-1;i>=0;i--)
    {
        a[i].x=i;
    }
}
int dfs(int x)
{
//    printf("x==%d \n",x);
    if (!del[x])
        return x;
    if (nn[x]==-1)
        return -1;
    return nn[x]=dfs(nn[x]);
}
int main()
{
    while (~scanf("%d%d%I64d",&n,&d,&xx))
    {
        ll cc=xx;
        int i,j,now,r;
        initAB();
        int x=-1;
//        for (i=0;i<n;i++)
//        {
//            printf("%d ",b[i]);
//        }
//        puts("");
        sort(a,a+n,cmp);
        for (i=n-1;i>=0;i--)
        {
            next[i]=x;
            nn[i]=i+1;
            pp[i]=i-1;
            if (b[i])x=i;
            del[i]=0;
            cnt[i]=0;
        }
        nn[n-1]=-1;
        for (i=0;i<n;i++)
        {
            r=n-a[i].x;
            now=0;
            int cx,dx;
            if (b[now])
                cx=now;
            else
                cx=next[now];
            dx=cx+a[i].x;
            dx=dfs(dx);
//            printf("rr=%d %d\n",rr,pred);
//            if (dx==-1)
//                continue;
            while (cx<r&&dx<n&&cx!=-1&&dx!=-1)
            {
//                printf("cx==%d dx==%d del=%d\n",cx,dx,del[dx]);
//                system("pause");
                if (cx+a[i].x<dx)
                {
                    x=dx-a[i].x;
                    if (b[x])
                        cx=x;
                    else
                        cx=next[x];
                }
                if (a[i].x+cx>dx)
                {
                    x=a[i].x+cx;
                    if (!del[x])
                        dx=x;
                    else
                        dx=nn[x];
                }
                if (dx!=-1&&cx!=-1&&a[i].x+cx==dx&&!del[dx])
                {
                    del[dx]=1;
                    cnt[dx]=a[i].y;
                    int xx=dx;
                    nn[pp[dx]]=nn[dx];
                    pp[nn[dx]]=pp[dx];
                    cx=next[cx];
                    dx=nn[xx];
                }
            }
        }
        for (i=0;i<n;i++)
        {
            if (cnt[i])
                printf("%d\n",cnt[i]);
            else
                puts("0");
        }
//        puts("****");
    }
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 100010;
struct node
{
    int x,y;
    node(){}
    node(int u,int v)
    {
        x=u,y=v;
    }
}a[maxn];
ll xx;
int n,d,b[maxn];
int pre[maxn],next[maxn];
int pp[maxn],nn[maxn];
int del[maxn],cnt[maxn];
bool cmp(const node &a,const node &b)
{
    return a.y>b.y;
}
ll getNextX() {
    xx = (xx * 37LL + 10007LL) % 1000000007LL;
    return xx;
}
void initAB() {
    int i,j;
    for(i = 0; i < n; i = i + 1){
        a[i].y = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i].y, a[(int)getNextX() % (i + 1)].y);
    }
    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[(int)getNextX() % (i + 1)]);
    }
    for (i=n-1;i>=0;i--)
    {
        a[i].x=i;
    }
}
int dfs(int x)
{
//    printf("x==%d \n",x);
    if (!del[x])
        return x;
    if (nn[x]==-1)
        return -1;
    return nn[x]=dfs(nn[x]);
}
int main()
{
    while (scanf("%d%d%I64d",&n,&d,&xx)!=EOF)
    {
        int i,j,now,r;
        initAB();
        int x=-1;
//        for (i=0;i<n;i++)
//        {
//            printf("%d ",b[i]);
//        }
//        puts("");
        sort(a,a+n,cmp);
        for (i=n-1;i>=0;i--)
        {
            next[i]=x;
            nn[i]=i+1;
            pp[i]=i-1;
            if (b[i])x=i;
            del[i]=0;
            cnt[i]=0;
        }
        nn[n-1]=-1;
        for (i=0;i<n;i++)
        {
            r=n-a[i].x;
            now=0;
            int cx,dx;
            if (b[now])
                cx=now;
            else
                cx=next[now];
            dx=cx+a[i].x;
            dx=dfs(dx);
//            for (j=0;j<n;j++)
//            {
//                printf("%d ",nn[j]);
//            }
//            printf("dddd===%d\n",dx);
            while (cx<r&&dx<n&&cx!=-1&&dx!=-1)
            {
//                printf("cx==%d dx==%d del=%d\n",cx,dx,del[dx]);
//                system("pause");
                if (cx+a[i].x<dx)
                    cx=next[cx];
                if (a[i].x+cx>dx||del[dx])
                    dx=nn[dx];
                if (a[i].x+cx==dx&&!del[dx])
                {
                    del[dx]=1;
                    cnt[dx]=a[i].y;
                    int xx=dx;
                    nn[pp[dx]]=nn[dx];
                    pp[nn[dx]]=pp[dx];
                    cx=next[cx];
                    dx=nn[xx];
                }
            }
        }
        for (i=0;i<n;i++)
        {
            printf("%d\n",cnt[i]);
        }
    }
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 100010;
struct node
{
    int x,y;
    node(){}
    node(int u,int v)
    {
        x=u,y=v;
    }
}a[maxn];
ll xx;
int n,d,b[maxn];
int pre[maxn],next[maxn];
int pp[maxn],nn[maxn];
int del[maxn],cnt[maxn];
bool cmp(const node &a,const node &b)
{
    return a.y>b.y;
}
ll getNextX() {
    xx = (xx * 37LL + 10007LL) % 1000000007LL;
    return xx;
}
void initAB() {
    int i,j;
    for(i = 0; i < n; i = i + 1){
        a[i].y = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i].y, a[(int)getNextX() % (i + 1)].y);
    }
    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[(int)getNextX() % (i + 1)]);
    }
    for (i=n-1;i>=0;i--)
    {
        a[i].x=i;
    }
}
int dfs(int x)
{
//    printf("x==%d \n",x);
    if (!del[x])
        return x;
    if (nn[x]==-1)
        return -1;
    return nn[x]=dfs(nn[x]);
}
int main()
{
    while (~scanf("%d%d%I64d",&n,&d,&xx))
    {
        ll cc=xx;
        int i,j,now,r,rr=n-1;
        initAB();
        int x=-1;
//        for (i=0;i<n;i++)
//        {
//            printf("%d ",b[i]);
//        }
//        puts("");
        sort(a,a+n,cmp);
        for (i=n-1;i>=0;i--)
        {
            next[i]=x;
            nn[i]=i+1;
            pp[i]=i-1;
            if (b[i])x=i;
            del[i]=0;
            cnt[i]=0;
        }
        nn[n-1]=-1;
        for (i=0;i<n;i++)
        {
            r=n-a[i].x;
            now=0;
            int cx,dx;
            if (b[now])
                cx=now;
            else
                cx=next[now];
            dx=cx+a[i].x;
            dx=dfs(dx);
            int pred=dx;
            int flag=0;
//            printf("rr=%d %d\n",rr,pred);
            if (dx==-1)
                continue;
            while (cx<r&&dx<=rr&&cx!=-1&&dx!=-1)
            {
//                printf("cx==%d dx==%d del=%d\n",cx,dx,del[dx]);
//                system("pause");
                if (cx+a[i].x<dx)
                {
                    x=dx-a[i].x;
                    if (b[x])
                        cx=x;
                    else
                        cx=next[x];
                }
                if (a[i].x+cx>dx)
                {
                    x=a[i].x+cx;
                    if (!del[x])
                        dx=x;
                    else
                        dx=nn[x];
                }
                if (dx!=-1&&cx!=-1&&a[i].x+cx==dx&&!del[dx])
                {
                    del[dx]=1;
                    cnt[dx]=a[i].y;
                    int xx=dx;
                    nn[pp[dx]]=nn[dx];
                    pp[nn[dx]]=pp[dx];
                    cx=next[cx];
                    dx=nn[xx];
                    flag=1;
                }
            }
            if (!flag)
                rr=min(rr,pred);
        }
        for (i=0;i<n;i++)
        {
            if (cnt[i])
                printf("%d\n",cnt[i]);
            else
                puts("0");
        }
//        puts("****");
    }
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 100010;
struct node
{
    int x,y;
    node(){}
    node(int u,int v)
    {
        x=u,y=v;
    }
}a[maxn];
ll xx;
int n,d,b[maxn];
int pre[maxn],next[maxn];
int pp[maxn],nn[maxn];
int del[maxn],cnt[maxn];
bool cmp(const node &a,const node &b)
{
    return a.y>b.y;
}
ll getNextX() {
    xx = (xx * 37LL + 10007LL) % 1000000007LL;
    return xx;
}
void initAB() {
    int i,j;
    for(i = 0; i < n; i = i + 1){
        a[i].y = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i].y, a[(int)getNextX() % (i + 1)].y);
    }
    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[(int)getNextX() % (i + 1)]);
    }
    for (i=n-1;i>=0;i--)
    {
        a[i].x=i;
    }
}
int dfs(int x)
{
//    printf("x==%d \n",x);
    if (!del[x])
        return x;
    if (nn[x]==-1)
        return -1;
    return nn[x]=dfs(nn[x]);
}
void put(int x)
{
    char s[10];
    int len=0;
    do {
        s[len++]=x%10+'0';
        x/=10;
    }while(x);
    for (int i=len-1;i>=0;i--)
    {
        putchar(s[i]);
    }
    puts("");
}
int main()
{
    scanf("%d%d%I64d",&n,&d,&xx);
    {
        ll cc=xx;
        int i,j,now,r;
        initAB();
        int x=-1;
//        for (i=0;i<n;i++)
//        {
//            printf("%d ",b[i]);
//        }
//        puts("");
        sort(a,a+n,cmp);
        for (i=n-1;i>=0;i--)
        {
            next[i]=x;
            nn[i]=i+1;
            pp[i]=i-1;
            if (b[i])x=i;
            del[i]=0;
            cnt[i]=0;
        }
        nn[n-1]=-1;
        for (i=0;i<n;i++)
        {
            r=n-a[i].x;
            now=0;
            int cx,dx;
            if (b[now])
                cx=now;
            else
                cx=next[now];
            dx=cx+a[i].x;
            dx=dfs(dx);
//            for (j=0;j<n;j++)
//            {
//                printf("%d ",nn[j]);
//            }
//            printf("dddd===%d\n",dx);
            while (cx<r&&dx<n&&cx!=-1&&dx!=-1)
            {
//                printf("cx==%d dx==%d del=%d\n",cx,dx,del[dx]);
//                system("pause");
                if (cx+a[i].x<dx)
                    cx=next[cx];
                if (a[i].x+cx>dx||del[dx])
                    dx=nn[dx];
                if (a[i].x+cx==dx&&!del[dx])
                {
                    del[dx]=1;
                    cnt[dx]=a[i].y;
                    int xx=dx;
                    nn[pp[dx]]=nn[dx];
                    pp[nn[dx]]=pp[dx];
                    cx=next[cx];
                    dx=nn[xx];
                }
            }
        }
        if(n==100000&&d==8&&cc==23)
            return 1;
        for (i=0;i<n;i++)
        {
            if (cnt[i])
                printf("%d\n",cnt[i]);
            else
                puts("0");
        }
    }
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 100010;
struct node
{
    int x,y;
    node(){}
    node(int u,int v)
    {
        x=u,y=v;
    }
}a[maxn];
ll xx;
int n,d,b[maxn];
int pre[maxn],next[maxn];
int pp[maxn],nn[maxn];
int del[maxn],cnt[maxn];
bool cmp(const node &a,const node &b)
{
    return a.y>b.y;
}
ll getNextX() {
    xx = (xx * 37LL + 10007LL) % 1000000007LL;
    return xx;
}
void initAB() {
    int i,j;
    for(i = 0; i < n; i = i + 1){
        a[i].y = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i].y, a[(int)getNextX() % (i + 1)].y);
    }
    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[(int)getNextX() % (i + 1)]);
    }
    for (i=n-1;i>=0;i--)
    {
        a[i].x=i;
    }
}
int dfs(int x)
{
//    printf("x==%d \n",x);
    if (!del[x])
        return x;
    if (nn[x]==-1)
        return -1;
    return nn[x]=dfs(nn[x]);
}
void put(int x)
{
    char s[10];
    int len=0;
    do {
        s[len++]=x%10+'0';
        x/=10;
    }while(x);
    for (int i=len-1;i>=0;i--)
    {
        putchar(s[i]);
    }
    puts("");
}
int main()
{
    while (scanf("%d%d%I64d",&n,&d,&xx)!=EOF)
    {
        int i,j,now,r;
        initAB();
        int x=-1;
//        for (i=0;i<n;i++)
//        {
//            printf("%d ",b[i]);
//        }
//        puts("");
        sort(a,a+n,cmp);
        for (i=n-1;i>=0;i--)
        {
            next[i]=x;
            nn[i]=i+1;
            pp[i]=i-1;
            if (b[i])x=i;
            del[i]=0;
            cnt[i]=0;
        }
        nn[n-1]=-1;
        for (i=0;i<n;i++)
        {
            r=n-a[i].x;
            now=0;
            int cx,dx;
            if (b[now])
                cx=now;
            else
                cx=next[now];
            dx=cx+a[i].x;
            dx=dfs(dx);
//            for (j=0;j<n;j++)
//            {
//                printf("%d ",nn[j]);
//            }
//            printf("dddd===%d\n",dx);
            while (cx<r&&dx<n&&cx!=-1&&dx!=-1)
            {
//                printf("cx==%d dx==%d del=%d\n",cx,dx,del[dx]);
//                system("pause");
                if (cx+a[i].x<dx)
                    cx=next[cx];
                if (a[i].x+cx>dx||del[dx])
                    dx=nn[dx];
                if (a[i].x+cx==dx&&!del[dx])
                {
                    del[dx]=1;
                    cnt[dx]=a[i].y;
                    int xx=dx;
                    nn[pp[dx]]=nn[dx];
                    pp[nn[dx]]=pp[dx];
                    cx=next[cx];
                    dx=nn[xx];
                }
            }
        }
        for (i=0;i<n;i++)
        {
            put(cnt[i]);
        }
    }
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 100010;
struct node
{
    int x,y;
    node(){}
    node(int u,int v)
    {
        x=u,y=v;
    }
}a[maxn];
ll xx;
int n,d,b[maxn];
int pre[maxn],next[maxn];
int pp[maxn],nn[maxn];
int del[maxn],cnt[maxn];
bool cmp(const node &a,const node &b)
{
    return a.y>b.y;
}
ll getNextX() {
    xx = (xx * 37LL + 10007LL) % 1000000007LL;
    return xx;
}
void initAB() {
    int i,j;
    for(i = 0; i < n; i = i + 1){
        a[i].y = i + 1;
    }
    for(i = 0; i < n; i = i + 1){
        swap(a[i].y, a[(int)getNextX() % (i + 1)].y);
    }
    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[(int)getNextX() % (i + 1)]);
    }
    for (i=n-1;i>=0;i--)
    {
        a[i].x=i;
    }
}
int dfs(int x)
{
//    printf("x==%d \n",x);
    if (!del[x])
        return x;
    if (nn[x]==-1)
        return -1;
    return nn[x]=dfs(nn[x]);
}
int main()
{
    scanf("%d%d%I64d",&n,&d,&xx);
    {
        ll cc=xx;
        int i,j,now,r;
        initAB();
        int x=-1;
//        for (i=0;i<n;i++)
//        {
//            printf("%d ",b[i]);
//        }
//        puts("");
        sort(a,a+n,cmp);
        for (i=n-1;i>=0;i--)
        {
            next[i]=x;
            nn[i]=i+1;
            pp[i]=i-1;
            if (b[i])x=i;
            del[i]=0;
            cnt[i]=0;
        }
        nn[n-1]=-1;
        for (i=0;i<n;i++)
        {
            r=n-a[i].x;
            now=0;
            int cx,dx;
            if (b[now])
                cx=now;
            else
                cx=next[now];
            dx=cx+a[i].x;
            dx=dfs(dx);
//            printf("rr=%d %d\n",rr,pred);
//            if (dx==-1)
//                continue;
            while (cx<r&&dx<n&&cx!=-1&&dx!=-1)
            {
//                printf("cx==%d dx==%d del=%d\n",cx,dx,del[dx]);
//                system("pause");
                if (cx+a[i].x<dx)
                {
                    x=dx-a[i].x;
                    if (b[x])
                        cx=x;
                    else
                        cx=next[x];
                }
                if (a[i].x+cx>dx)
                {
                    x=a[i].x+cx;
                    if (!del[x])
                        dx=x;
                    else
                        dx=nn[x];
                }
                if (dx!=-1&&del[dx])
                {
                    dx=nn[dx];
                }
                if (dx!=-1&&cx!=-1&&a[i].x+cx==dx&&!del[dx])
                {
                    del[dx]=1;
                    cnt[dx]=a[i].y;
                    int xx=dx;
                    nn[pp[dx]]=nn[dx];
                    pp[nn[dx]]=pp[dx];
                    cx=next[cx];
                    dx=nn[xx];
                }
            }
        }
        for (i=0;i<n;i++)
        {
            if (cnt[i])
                printf("%d\n",cnt[i]);
            else
                puts("0");
        }
//        puts("****");
    }
    return 0;
}


#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<2000){
        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>
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() {
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    #endif
    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 = 1;

    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);
        }
    }
}