#!/usr/bin/env python3 # RTE, because this fails to solve a few cases. # 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). a, b, c, v = map(int, input().split()) # handle v=1 separately if v == 1: print(4) print(0, 0, 0) print(1, 0, 0) print(0, 1, 0) print(0, 0, 1) exit(0) # 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 def factor(x): fs = [] p = 2 while p * p <= x: while x % p == 0: fs.append(p) x //= p p += 1 if x > 1: fs.append(x) return fs def partition_factors(fs, x=1, y=1, z=1): if x > a or y > b or z > c: return None if len(fs) == 0: return (x, y, z) f = fs[-1] fs = fs[:-1] return ( partition_factors(fs, x * f, y, z) or partition_factors(fs, x, y * f, z) or partition_factors(fs, x, y, z * f) ) # Greedily find the largest possible takeouts. r = [(0, 0, 0)] * 4 for i in range(4): for w in range(t, 0, -1): fs = factor(w) p = partition_factors(fs) if p: t -= w r[i] = p break assert t == 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)