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: Runtime Error)

# include <bits/stdc++.h>

# define F first    
# define S second
# define mp make_pair
// everything go according to my plan      
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right  

using namespace std;

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

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {   
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") { 
  if (fopen (in, "r"))
    freopen (in, "r", stdin);
  else
    cerr << "Warning: Input file not found" << endl;
}
int n, L, T;

int x[Sz], w[Sz];

void solve (int x[], int w[], int p[]) {      
  static vec<ll> a;
  a.clear();
  for (int i = 1; i <= n; i++) {
    if (w[i])
      a.pb (x[i]);
  }    
  int len = sz(a);
  for (int i = 0; i < len; i++)
    a.pb (a[i] + L);
  for (int i = 1; i <= n; i++) {
    if (!w[i]) {
      ll j = i;
      j += (2*T/L) * 1ll * sz(a);
      if (sz(a)) {
        j += upper_bound (a.begin(), a.end(), x[i] + (2ll * T % L)) - upper_bound (a.begin(), a.end(), x[i]);
      }
      if (j > n)
        j -= n;
      p[i] = j;
    }
  } 
}

int main()
{
  #ifdef Local
    localInput();
  #endif
  Read_rap();      
  cin >> n >> L >> T;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> w[i];
    w[i]--;
  }
  int p[2][Sz];
  int ans[Sz];
  for (int t = 0; t < 2; t++) {
    solve (x, w, p[t]); 
    for (int i = 1; i <= n/2; i++) {
      swap (x[i], x[n - i + 1]);
      swap (w[i], w[n - i + 1]);
    }
    for (int i = 1; i <= n; i++)
      x[i] = (L-x[i]) % L, w[i] ^= 1;
  }
  /*
  for (int i = 0; i < 2; i++) {
    for (int j = 1; j <= n; j++)
      cout << p[i][j] << ' ';
    cout << endl;
  }
  */             

  for (int i = 1; i <= n; i++)
    if (!w[i]) 
      ans[p[0][i]] = (x[i] + T) % L;
    else
      ans[n - p[1][n - i + 1] + 1] = ((x[i] - T) % L + L) % L ;
  
  for (int i = 1; i <= n; i++)
    cout << ans[i] << endl;

  return 0;
}






// Coded by Z..