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>

#define FOR(i,a,b) for (int i = (int)(a); i < (int)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define x first
#define y second

#define TRACE(x) cerr << #x << " = " << x << endl
#define _ << " _ " <<

using namespace std;

typedef long long ll;
typedef pair<ll, int> pii;

int n;
ll l, t;
pii x[100005];

ll f(ll a){
  a %= l;
  if (a < 0) return a+l;
  return a;
}

set<pii> Sn, Sp;

ll location(int dir, ll loc, ll tm){

  while (true){
    loc = f(loc);
    int nxt;
    if (dir == 1)
      nxt = Sn.lower_bound({f(loc+tm), 1e9})->y;
    else
      nxt = (--Sp.lower_bound({f(loc-tm), -1}))->y;
    ll loc2 = f(x[nxt].x + tm * x[nxt].y);

    if (dir == 1){
      if (loc2 <= loc) loc2 += l;
      loc2 = (loc+loc2) / 2;
    } else {
      if (loc2 >= loc) loc2 -= l;
      loc2 = (loc+loc2) / 2;
    }

    ll del = abs(loc-loc2);
    if (tm+del > t) break;
    tm += del;
    loc = loc2;
    dir = -dir;
    
  }

  return f(loc + (t-tm) * dir);
  
}

ll location(int id){
  return location(x[id].y, x[id].x, 0);
}

int main(){
  ios_base::sync_with_stdio(false);

  cin >> n >> l >> t;
  REP(i,n) cin >> x[i].x >> x[i].y, x[i].y = x[i].y == 1 ? 1 : -1;

  {
    bool check = true;
    REP(i,n) if (x[i].y != x[0].y) check = false;
    if (check){
      REP(i,n) cout << f(x[i].x + t * x[i].y) << endl;
      return 0;
    }
  }

  l *= 2;
  t *= 2;
  t %= 2*l;
  REP(i,n) x[i].x *= 2;

  REP(i,n){
    if (x[i].y == 1)
      Sp.insert({x[i].x, i}),
	Sp.insert({x[i].x+l, i}),
	Sp.insert({x[i].x-l, i});
    else
      Sn.insert({x[i].x, i}),
	Sn.insert({x[i].x+l, i}),
	Sn.insert({x[i].x-l, i});
  }

  ll a = location(0);
  ll b = location(1);

  vector<ll> all;
  REP(i,n) all.pb(f(x[i].x + x[i].y * t));
  sort(all.begin(), all.end());

  if (all.back() == a && all.front() == b)
    all.insert(all.begin(), a), all.pop_back();

  int id = -1;
  REP(i,n-1) if (all[i] == a && all[i+1] == b) id = i;
  assert(id != -1);

  FOR(i,id,n) cout << all[i]/2 << endl;
  FOR(i,0,id) cout << all[i]/2 << endl;

  return 0;
}