/* 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
{
public static int NumArrNK(int n, int k) {
int out = 1;
for (int i = 0; i <= k - 1; i++)
out *= n - i;
return out;
}
public static String ArrByR
(int n,
int k,
int x
){ String s
= "ABCDEFGHJKLMNOPQ"; int[] Dig = new int[n];
int id, ank;
for (int i = 0; i < n; i++)
Dig[i] = i;
for (int i = 1; i <= k; i++) {
ank = NumArrNK(n - i, k - i); //might be optimized
id = x / ank;
x = x % ank; //prepare for the next round
out = out + s.charAt(Dig[id]);
for (int j = id; j < n - i; j++)
Dig[j] = Dig[j + 1];
}
return out;
}
{
int dups = 0;
for (int i = 0; i < 60; i++) {
//String s = getS(i, 5, 3);
System.
out.
print(i
+ ": " + s
);
for (int j = 0; j < s.length() - 1; j++) {
for (int k = j + 1; k < s.length(); k++) {
if (s.charAt(k) == s.charAt(j)) {
j = s.length();
k = j;
dups++;
}
}
}
}
System.
out.
println("dups: " + dups
); }
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgSWRlb25lCnsKCXB1YmxpYyBzdGF0aWMgaW50IE51bUFyck5LKGludCBuLCBpbnQgaykgewogICAgICAgIGludCBvdXQgPSAxOwoKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8PSBrIC0gMTsgaSsrKQogICAgICAgICAgICBvdXQgKj0gbiAtIGk7CgogICAgICAgIHJldHVybiBvdXQ7CiAgICB9CgogICAgcHVibGljIHN0YXRpYyBTdHJpbmcgQXJyQnlSKGludCBuLCBpbnQgaywgaW50IHgpewogICAgICAgIFN0cmluZyBzID0gIkFCQ0RFRkdISktMTU5PUFEiOwogICAgICAgIGludFtdIERpZyA9IG5ldyBpbnRbbl07CgogICAgICAgIGludCBpZCwgYW5rOwoKICAgICAgICBTdHJpbmcgb3V0ID0gIiI7CgogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKQogICAgICAgICAgICBEaWdbaV0gPSBpOwoKICAgICAgICBmb3IgKGludCBpID0gMTsgaSA8PSBrOyBpKyspIHsKCiAgICAgICAgICAgIGFuayA9IE51bUFyck5LKG4gLSBpLCBrIC0gaSk7ICAvL21pZ2h0IGJlIG9wdGltaXplZAogICAgICAgICAgICBpZCA9IHggLyBhbms7CiAgICAgICAgICAgIHggPSB4ICUgYW5rOyAgIC8vcHJlcGFyZSBmb3IgdGhlIG5leHQgcm91bmQKICAgICAgICAgICAgb3V0ID0gb3V0ICsgcy5jaGFyQXQoRGlnW2lkXSk7CgogICAgICAgICAgICBmb3IgKGludCBqID0gaWQ7IGogPCBuIC0gaTsgaisrKQogICAgICAgICAgICAgICAgRGlnW2pdID0gRGlnW2ogKyAxXTsKCiAgICAgICAgfQoKICAgICAgICByZXR1cm4gb3V0OwogICAgfQogICAgCglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbiAoU3RyaW5nW10gYXJncykgdGhyb3dzIGphdmEubGFuZy5FeGNlcHRpb24KCXsKCQlpbnQgZHVwcyA9IDA7CgogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgNjA7IGkrKykgewogICAgICAgICAgICAvL1N0cmluZyBzID0gZ2V0UyhpLCA1LCAzKTsKICAgICAgICAgICAgU3RyaW5nIHMgPSBBcnJCeVIoNSwgMywgaSk7CgogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50KGkgKyAiOiAiICsgcyk7CgogICAgICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IHMubGVuZ3RoKCkgLSAxOyBqKyspIHsKICAgICAgICAgICAgICAgIGZvciAoaW50IGsgPSBqICsgMTsgayA8IHMubGVuZ3RoKCk7IGsrKykgewogICAgICAgICAgICAgICAgICAgIGlmIChzLmNoYXJBdChrKSA9PSBzLmNoYXJBdChqKSkgewogICAgICAgICAgICAgICAgICAgICAgICBqID0gcy5sZW5ndGgoKTsKICAgICAgICAgICAgICAgICAgICAgICAgayA9IGo7CiAgICAgICAgICAgICAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnQoIkBkdXAhIik7CiAgICAgICAgICAgICAgICAgICAgICAgIGR1cHMrKzsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCk7CiAgICAgICAgfQoKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oImR1cHM6ICIgKyBkdXBzKTsKCX0KfQ==