Buggy python submission (verdict: Time Limit Exceeded):
N, L, T = [int(i) for i in input().split()]

ants = list(map(lambda x: [x[0] * 2, x[1]], [[int(i) for i in input().split()] for j in range(N)]))

for i in range(T * 2):
	for j in range(N):
		if ants[j][1] == 1:
			if ants[j][0] == 2 * L - 1:
				ants[j][0] = 0
			else:
				ants[j][0] += 1
			if j == N - 1:
				if ants[0][0] == ants[j][0]:
					ants[0][1] = 1
					ants[j][1] = 2
		else:
			if ants[j][0] == 0:
				ants[j][0] = 2 * L - 1
			else:
				ants[j][0] -= 1
			if j != 0:
				if ants[j - 1][0] == ants[j][0]:
					ants[j - 1][1] = 2
					ants[j][1] = 1

for i in range(N):
	print(ants[i][0] // 2)

Fixed submission:
N, L, T = map(int, input().split())
X = []
W = []
for _ in range(N):
    x, w = map(int, input().split())
    X.append(x)
    if w == 2:
        w = -1
    W.append(w)

C = 0
for i in range(1, N):
    if W[i] != W[0]:
        C += T // (L / 2)
        if W[0] == 1:
            D = X[i] - X[0]
        else:
            D = X[0] + L - X[i]
        if T % (L / 2) * 2 >= D:
            C += 1

for i in range(N):
    X[i] = (X[i] + T * W[i]) % L

x = X[0]

X.sort()

ng = -1
ok = N
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if X[mid] >= x:
        ok = mid
    else:
        ng = mid
if W[0] == 1 and ok < N-1:
    if X[ok] == X[ok+1]:
        ok += 1

start = int((ok - C * W[0]) % N)
for i in X[start:]:
    print(i)
for i in X[:start]:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
N, L, T = [int(i) for i in input().split()]

ants = list(map(lambda x: [x[0] * 2, x[1]], [[int(i) for i in input().split()] for j in range(N)]))

for i in range(T * 2):
	for j in range(N):
		if ants[j][1] == 1:
			if j != N - 1:
				if ants[j][0] == 2 * L - 1:
					if ants[j + 1][0] == 1 and ants[j + 1][1] == 2:
						ants[j][0] = 0
						ants[j][1] = 2
						ants[j + 1][0] = 2 * L - 1
						ants[j + 1][1] = 1
					else:
						ants[j][0] = 0
				elif ants[j][0] == 2 * L - 2:
					if ants[j + 1][0] == 0 and ants[j + 1][1] == 2:
						ants[j][0] = 2 * L - 1
						ants[j][1] = 2
						ants[j + 1][0] = 2 * L - 2
						ants[j + 1][1] = 1
					else:
						ants[j][0] = 2 * L - 1
				else:
					if ants[j + 1][0] == ants[j][0] + 2 and ants[j + 1][1] == 2:
						ants[j][0] += 1
						ants[j][1] = 2
						ants[j + 1][0] -= 2
						ants[j + 1][1] = 1
					else:
						ants[j][0] += 1
			else:
				if ants[j][0] == 2 * L - 1:
					ants[j][0] = 0
				else:
					ants[j][0] += 1
				if ants[0][0] == ants[j][0]:
					ants[0][1] = 1
					ants[j][1] = 2
		else:
			if ants[j][0] == 0:
				ants[j][0] = 2 * L - 1
			else:
				ants[j][0] -= 1

for i in range(N):
	print(ants[i][0] // 2)

Fixed submission:
N, L, T = map(int, input().split())
X = []
W = []
for _ in range(N):
    x, w = map(int, input().split())
    X.append(x)
    if w == 2:
        w = -1
    W.append(w)

C = 0
for i in range(1, N):
    if W[i] != W[0]:
        C += T // (L / 2)
        if W[0] == 1:
            D = X[i] - X[0]
        else:
            D = X[0] + L - X[i]
        if T % (L / 2) * 2 >= D:
            C += 1

for i in range(N):
    X[i] = (X[i] + T * W[i]) % L

x = X[0]

X.sort()

ng = -1
ok = N
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if X[mid] >= x:
        ok = mid
    else:
        ng = mid
if W[0] == 1 and ok < N-1:
    if X[ok] == X[ok+1]:
        ok += 1

start = int((ok - C * W[0]) % N)
for i in X[start:]:
    print(i)
for i in X[:start]:
    print(i)