LG-P2391
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1000010;
int n, m, p, q;
int fa[N], c[N];
int find(int x)
{
if (x != fa[x]) fa[x] = find(fa[x]);
return fa[x];
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m >> p >> q;
for (int i = 1; i <= n; i ++ ) fa[i] = i;
for (int i = m; i >= 1; i -- )
{
int l = (i * p + q) % n + 1, r = (i * q + p) % n + 1;
if (l > r) swap(l, r);
for (int j = r; j >= l; )
{
int t = find(j);
if (t == j)
{
c[j] = i;
fa[j] = find(j - 1);
}
j = fa[j];
}
}
for (int i = 1; i <= n; i ++ )
cout << c[i] << '\n';
}