#!/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): x = t and min(a, t) y = t and min(b, t//x) z = t and min(c, t//x//y) t -= x*y*z r[i] = (x, y, z) # handle edge cases if t != 0: if v == 1: ps = [(0,0,0), (1,0,0), (0,1,0), (0,0,1)] elif (a,b,c,v) == (2,2,2,25): ps = [(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 else: 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)