Problem:
Score : 700 points

Problem Statement

There is a circle with a circumference of L.
Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point.
On this circumference, there are N ants.
These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i.

The N ants have just started walking.
For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2.
Every ant walks at a constant speed of 1 per second.
Sometimes, two ants bump into each other.
Each of these two ants will then turn around and start walking in the opposite direction.

For each ant, find its position after T seconds.

Constraints

All input values are integers.

1 \leq N \leq 10^5

1 \leq L \leq 10^9

1 \leq T \leq 10^9

0 \leq X_1 < X_2 < ... < X_N \leq L - 1

1 \leq W_i \leq 2

Input

The input is given from Standard Input in the following format:

N L T
X_1 W_1
X_2 W_2
:
X_N W_N

Output

Print N lines.
The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive.

Sample Input 1

3 8 3
0 1
3 2
6 1

Sample Output 1

1
3
0

1.5 seconds after the ants start walking, ant 1 and 2 bump into each other at coordinate 1.5.
1 second after that, ant 1 and 3 bump into each other at coordinate 0.5.
0.5 seconds after that, that is, 3 seconds after the ants start walking, ants 1, 2 and 3 are at coordinates 1, 3 and 0, respectively.

Sample Input 2

4 20 9
7 2
9 1
12 1
18 1

Sample Output 2

7
18
18
1

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> namespace mp = boost::multiprecision; //mp::cpp_intで宣言
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////

struct ant{
    ll x;
    ll w;
    ll num;
};
bool comp(ant a,ant b){
    if(a.x<b.x)return true;
    else return false;
}

int main(){
    ll n,l,t;cin>>n>>l>>t;
    ant an[n];
    rep(i,0,n-1){
        cin>>an[i].x>>an[i].w;
        an[i].num=i;
    }
    vector<ant>v;
    rep(i,0,n-1){
        ll c;
        if(an[i].w==1){
            c=(an[i].x+t)%l;
        }else{
            c=(100000*l+an[i].x-t)%l;
            if(c<0)c+=l;
        }
        ant a;a.x=c;a.w=an[i].w;a.num=i;
        v.pb(a);
    }
    sort(v.begin(),v.end(),comp);
    
    ll count=0;
    ll pos;
    rep(i,0,n-1){
        if(v[i].num==0)pos=i;
    }
    ll init=-1;
    if(an[0].w==1){
        rep(i,1,n-1){
            if(an[i].w==2){
                ll q=2*t-(an[i].x-an[0].x);
                if(q<0)continue;
                else{
                    ll c=q/l;
                    count+=c+1;
                }
            }
        }
        init=(pos-count+n*1000000)%n;
        if(init<0)init+=n;
    }else{
        rep(i,1,n-1){
            if(an[i].w==1){
                ll q=2*t-(-an[i].x+l+an[0].x);
                if(q<0)continue;
                else{
                    ll c=q/l;
                    count+=c+1;
                }
            }
        }
        init=(pos+count+n*5)%n;
        if(init<0)init+=n;
    }
    //cout<<pos<<" "<<count<<" "<<init<<endl;
    rep(i,init,n-1){
        cout<<v[i].x<<endl;
    }
    rep(i,0,init-1){
        cout<<v[i].x<<endl;
    }
    return 0;
}