#!/usr/bin/env python3
import sys
import random


# simulates a path that the cloud takes and determines observations depending on where the cloud is.

n = int(sys.argv[1]) # number of observations
k = int(sys.argv[2]) # number of direction changes in the path
w = int(sys.argv[3]) # upper bound of the eventual width
m = int(sys.argv[4]) # maximal value of time/position
random.seed(int(sys.argv[5]))

assert 1 <= k

path = [(0, random.randint(0,m))]
for i in range(k):
    direction = 1 if random.randint(0,m) > path[-1][1] else -1
    r = random.randint(1,min(m - path[-1][1] if direction == 1 else path[-1][1],(m - path[-1][0])//(k-i)))
    path.append((path[-1][0] + r, path[-1][1] + r*direction))

m = path[-1][0]-1
if m < 2*n:
    times = random.sample(list(range(m)), k=n)
else:
    times = set()
    while len(times) < n:
        t = random.randint(0,m)
        if t not in times:
            times.add(t)
    times = list(times)
random.shuffle(times)

print(n)
for t in times:
    l,h = 0,k+1
    while h-l>1:
        mid = (h+l)//2
        if path[mid][0] <= t:
            l = mid
        else:
            h = mid
    direction = 1 if path[h][1] > path[l][1] else -1
    cloud_pos = path[l][1] + direction * (t - path[l][0])
    print(t,cloud_pos + random.randint(-w//2,w//2))
