/* 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
{
{
// your code goes here
int bits,len,i,n;
final int MAX_BITS = 9; //4;
final int max_code = 287; //8;
long code;
long[] bl_count = new long[MAX_BITS+1],
next_code = new long[MAX_BITS+1];
Tree[] tree = new Tree[max_code+1];
/*
tree[0] = new Tree(0, 0);
tree[1] = new Tree(1, 3);
tree[2] = new Tree(2, 3);
tree[3] = new Tree(3, 3);
tree[4] = new Tree(4, 3);
tree[5] = new Tree(5, 3);
tree[6] = new Tree(6, 2);
tree[7] = new Tree(7, 4);
tree[8] = new Tree(8, 4);
*/
for (i = 0; i < 144; i++)
tree[i] = new Tree(i, 8);
for (; i < 256; i++)
tree[i] = new Tree(i, 9);
for (; i < 280; i++)
tree[i] = new Tree(i, 7);
for (; i < 288; i++)
tree[i] = new Tree(i, 8);
//Step1
for (i = 0; i < tree.length; i++) {
bl_count[tree[i].Len]++;
}
for (i = 2; i < bl_count.length; i++)
System.
out.
printf("%d: %d\n", i, bl_count
[i
]);
//Step2
code = 0;
bl_count[0] = 0;
for (bits = 1; bits <= MAX_BITS; bits++) {
code = (code + bl_count[bits-1]) << 1;
next_code[bits] = code;
}
for (i = 1; i < next_code.length; i++)
System.
out.
printf("%d: %d\n", i, next_code
[i
]);
//Step3
for (n = 0; n <= max_code; n++) {
len = tree[n].Len;
if (len != 0) {
tree[n].Code = next_code[len];
next_code[len]++;
}
}
for (i = 0; i <= max_code; i++) {
String s
= "0000000000" + Long.
toString(tree
[i
].
Code,
2); s = s.substring(s.length() - tree[i].Len);
System.
out.
printf("%03d: ", i
); }
}
public static class Tree {
public int Len = 0;
public long Code = 0;
public Tree(long code, int len) {
Len = len; Code = code;
}
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5n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