/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
static char[] pool = new char[]{'1', '2', '3'};
public static void buildStrings(char[] root, int length)
{
// allocate an array to hold our counts:
int[] pos = new int[length];
char[] combo = new char[length];
for(int i = 0; i < length; i++)
combo[i] = root[0];
while(true)
{
// output the current combinations:
// move on to the next combination:
int place = length - 1;
while(place >= 0)
{
if(++pos[place] == root.length)
{
pos[place] = 0;
combo[place] = root[0];
place--;
}
else
{
combo[place] = root[pos[place]];
break;
}
}
if(place < 0)
break;
}
}
{
// your code goes here
buildStrings(pool, 2);
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgSWRlb25lCnsKCXN0YXRpYyBjaGFyW10gcG9vbCA9IG5ldyBjaGFyW117JzEnLCAnMicsICczJ307CgoJcHVibGljIHN0YXRpYyB2b2lkIGJ1aWxkU3RyaW5ncyhjaGFyW10gcm9vdCwgaW50IGxlbmd0aCkKCXsKCQkvLyBhbGxvY2F0ZSBhbiBhcnJheSB0byBob2xkIG91ciBjb3VudHM6CgkJaW50W10gcG9zID0gbmV3IGludFtsZW5ndGhdOwoJCWNoYXJbXSBjb21ibyA9IG5ldyBjaGFyW2xlbmd0aF07CgkJZm9yKGludCBpID0gMDsgaSA8IGxlbmd0aDsgaSsrKQoJCSAgICBjb21ib1tpXSA9IHJvb3RbMF07CgkJICAgIAoJCXdoaWxlKHRydWUpCgkJewoJCQkvLyBvdXRwdXQgdGhlIGN1cnJlbnQgY29tYmluYXRpb25zOgoJCQlTeXN0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