Triple tree

Generate triples (a,b,c) satisfying a^2+b^2+c^2 = k(ab+bc+ca)+1 by two sweep operations from (1,k,k+k^2), then greedily print triples whose numbers are all new.

Hard9MathNumber theorySortingBrute forceNo attempts yetTime limit1sMemory limit512 MB

Problem

For an integer kk greater than 1, infinitely many triples of positive integers (a,b,c)(a, b, c) satisfy a2+b2+c2=k(ab+bc+ca)+1.a^2 + b^2 + c^2 = k(ab + bc + ca) + 1.

The triple (1,k,k+k2)(1, k, k + k^2) satisfies the equation. If a triple (a,b,c)(a, b, c) with a<b<ca < b < c satisfies it, then the two triples (b,  c,  k(b+c)a),(a,  c,  k(a+c)b)(b,\; c,\; k(b + c) - a), \qquad (a,\; c,\; k(a + c) - b) satisfy it as well, and each of them is already written in increasing order. Let SS be the set of all triples obtained from (1,k,k+k2)(1, k, k + k^2) by repeating these two operations.

List the triples of SS in increasing order of their largest number. When two triples share the same largest number, the one with the smaller middle number comes first, and when the middle numbers are equal too, the one with the smaller smallest number comes first. Walk through the triples in this order, keeping a set UU of the numbers printed so far. When none of the three numbers is in UU, print the triple and add its three numbers to UU. When at least one of them is in UU, skip the triple. Find the first nn triples printed this way.

The 3n3n printed numbers are pairwise distinct, and none of them has more than 100 digits.

Input

The first line contains the integers kk and nn, separated by a space. (2k10002 \le k \le 1000, 1n10001 \le n \le 1000)

Output

Print nn lines, giving the triples in the order defined above. On each line print the three numbers of one triple in increasing order, separated by spaces.