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<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>

namespace lib
{
	template<std::uint64_t Mod>struct modnum;
	template<class T>constexpr T pow(T base, std::size_t p)
	{
		if (p == 0)
		{
			return T(1);
		}
		else if (p == 1)
		{
			return base;
		}
		else if (p == 2)
		{
			return base*base;
		}
		else if (p % 2 == 0)
		{
			return pow(pow(base, p / 2), 2);
		}
		else
		{
			return pow(pow(base, p / 2), 2)*base;
		}
	}
	template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod> const&);

	template<std::uint64_t Mod>struct modnum
	{
		static constexpr auto mod = Mod;
		std::uint64_t val;
		modnum() = default;
		constexpr modnum(std::uint64_t v) :val(v)
		{

		}

		constexpr modnum& operator+=(modnum const& v)
		{
			val += v.val;
			val %= mod;
			return *this;
		}
		constexpr modnum& operator-=(modnum const& v)
		{
			val += mod - v.val;
			val %= mod;
			return *this;
		}
		constexpr modnum& operator*=(modnum const& v)
		{
			val *= v.val;
			val %= mod;
			return *this;
		}
		constexpr modnum& operator/=(modnum const& v)
		{
			return operator*=(inverse(v));
		}
	};
	template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs)
	{
		return lhs += rhs;
	}
	template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs)
	{
		return lhs -= rhs;
	}
	template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs)
	{
		return lhs *= rhs;
	}
	template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs)
	{
		return lhs /= rhs;
	}

	template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod>const& base)
	{
		return pow(base, Mod - 2);
	}

	template<class T>constexpr auto clamp(T v)
	{
		return std::max(v, T());
	}
	template<class T>void sort(std::vector<T>& vec)
	{
		std::sort(vec.begin(), vec.end());
	}

	template<class T>auto lower_bound(std::vector<T>const& vec, T v)
	{
		return std::distance(vec.begin(), std::lower_bound(vec.begin(), vec.end(), v));
	}

	template<class Tag>struct dmod
	{
		std::uint64_t val;
		static std::uint64_t mod;
		dmod(std::uint64_t v = 0) :val(v)
		{

		}
		dmod& operator+=(dmod const& rhs)
		{
			val += rhs.val;
			val %= mod;
			return *this;
		}
		dmod& operator-=(dmod const& rhs)
		{
			val += mod - rhs.val;
			val %= mod;
			return *this;
		}
		dmod& operator*=(dmod const& rhs)
		{
			val *= rhs.val;
			val %= mod;
			return *this;
		}
	};
	template<class Tag>dmod<Tag> operator+(dmod<Tag> lhs, dmod<Tag> const& rhs)
	{
		return lhs += rhs;
	}
	template<class Tag>dmod<Tag> operator-(dmod<Tag> lhs, dmod<Tag> const& rhs)
	{
		return lhs -= rhs;
	}
	template<class Tag>dmod<Tag> operator*(dmod<Tag> lhs, dmod<Tag> const& rhs)
	{
		return lhs *= rhs;
	}
	template<class Tag>std::uint64_t dmod<Tag>::mod;

	struct scope_exit
	{
		std::function<void(void)> func;
		scope_exit(std::function<void(void)> f) :func(f)
		{

		}
		~scope_exit()
		{
			func();
		}
	};

	template<int val>using int_tag = std::integral_constant<int, val>;
}

void Main();
int main()	
{
	std::cin.sync_with_stdio(false);
	Main();
}

typedef lib::modnum<1000000007> mod_t;

typedef lib::dmod<lib::int_tag<0>> N_t;
typedef lib::dmod<lib::int_tag<1>> L_t;
typedef lib::dmod<lib::int_tag<2>> L2_t;
N_t count(L_t x, L_t y, L_t T)
{
	auto d = 2 * (T.val - (y - x).val / 2.0) / L_t::mod;
	return d + 1;
}
N_t rcount(L_t x, L_t y, L_t T)
{
	return count(x, L_t(2)*x - y, T);
}

void Main()
{
	std::int64_t N, L, T, X, W;
	std::cin >> N >> L >> T >> X >> W;
	L_t::mod = L;
	N_t::mod = N;
	L2_t::mod = 2 * L;
	std::vector<std::int64_t> result;
	if (W == 1)
	{
		result.emplace_back((L_t(X) + L_t(T)).val);
	}
	else
	{
		result.emplace_back((L_t(X) - L_t(T)).val);
	}
	auto start = result.front();
	N_t h{};
	for (int i = 1; i < N; ++i)
	{
		L_t x;
		int w;
		std::cin >> x.val >> w;
		if (w == 1)
		{
			result.emplace_back((L_t(x) + L_t(T)).val);
			if (W == 2)
			{
				h -= rcount(X, x, T) + N_t(2 * (T / L));
			}
		}
		else
		{
			result.emplace_back((L_t(x) - L_t(T)).val);
			if (W == 1)
			{
				h += count(X, x, T) + N_t(2 * (T / L));
			}
		}
	}
	lib::sort(result);
	std::int64_t s = lib::lower_bound(result, start);
	for (int i{}; i < N; ++i)
	{
		std::cout << result[(N_t(s) - h + N_t(i)).val] << std::endl;
	}
	//std::cout << start << " " << h.val << " " << s << std::endl;
}