#!/usr/bin/env python3 # Algorithm: # 1. Shrink the bounding box as much as possible. # The wasted space `t` is now at most 6*a*b <= 6e12 (these numbers can be factored quickly) # 2. Fill the box with a tetrahedron - that leaves 4 corners where we can take things out. # 3. Find the largest number <= t that is a product of x,y,z with x<=a, y<=b, # z<=c, and cut this away from one of the corners. # 4. Repeat this 4 times (for each of the 4 corners). # # v=1 and (2,2,2,25) are the only edge cases. a, b, c, v = map(int, input().split()) # Make the bounding box tight. while 6 * (a - 1) * b * c >= v: a -= 1 while 6 * a * (b - 1) * c >= v: b -= 1 while 6 * a * b * (c - 1) >= v: c -= 1 # t <= 6*10^12 t = 6 * a * b * c - v # Greedily find the largest possible takeouts. r = [(0, 0, 0)] * 4 for i in range(4): for w in range(t, 0, -1): if i == 0: p = (a, b, t//a//b) if i == 1: p = (1, b, t//b) if i == 2: p = (1, 1, min(t, c)) if i == 3: p = (1, 1, min(t, c)) if p[0] * p[1] * p[2] > t: p = (0,0,0) t -= p[0] * p[1] * p[2] r[i] = p # handle edge cases if t != 0: if v == 1: vertices = [(0,0,0), (1,0,0), (0,1,0), (0,0,1)] elif (a,b,c,v) == (2,2,2,25): vertices = [(1,0,0),(0,1,0),(1,1,0),(0,0,1),(0,2,1),(2,0,1),(2,2,1),(0,0,2),(2,0,2)] else: assert t==0 print(len(vertices)) for p in vertices: print(*p) exit(0) cs = [(0, 0, 0), (0, b, c), (a, 0, c), (a, b, 0)] ps = {(a, 0, 0), (0, b, 0), (0, 0, c), (a, b, c)} for p, q in zip(cs, r): for i in range(3): x = [*p] x[i] = q[i] if x[i] == 0 else x[i] - q[i] ps.add((*x,)) print(len(ps)) for p in ps: print(*p)