import java.util.*;
public class generator {
private final int MIN_W = 2;
private final int MAX_W = 10;
private final int MIN_H = 2;
private final int MAX_H = 10;
private final int MIN_K = 10000;
private final int MAX_K = 100000;
private int h;
private int w;
private String[] puzzle;
private Random random;
private int randomIntBetween(int lower, int upper) {
return lower + random.nextInt(upper - lower + 1);
}
private String[] randomPuzzle(int h, int w, int k) {
char[] chars = new char[h*w - 1];
for(int i = 0; i < chars.length; ++i)
chars[i] = (char)randomIntBetween('a', 'z');
Arrays.sort(chars);
char[][] frame = new char[h][w];
for(int i = 0; i < chars.length; ++i)
frame[i/w][i%w] = chars[i];
frame[h - 1][w - 1] = '_';
int r = h - 1;
int c = w - 1;
for(int i = 0; i < k; ++i)
{
int rr = r;
int cc = c;
while(rr == r && cc == c)
{
if(randomIntBetween(0, 1) == 0)
rr = randomIntBetween(0, h - 1);
else
cc = randomIntBetween(0, w - 1);
}
int len = Math.abs(rr - r) + Math.abs(cc - c);
int dr = (rr - r)/len;
int dc = (cc - c)/len;
for(int j = 0; j < len; ++j)
{
frame[r][c] = frame[r + dr][c + dc];
r += dr;
c += dc;
}
frame[r][c] = '_';
}
String[] res = new String[h];
for(int i = 0; i < h; ++i)
res[i] = new String(frame[i]);
return res;
}
private void generate(long seed) {
if (seed == 1) { // sample case
h = 2;
w = 3;
puzzle = new String[] {
"hot",
"_at"
};
return;
}
random = new Random(seed);
h = randomIntBetween(MIN_H, MAX_H);
w = randomIntBetween(MIN_W, MAX_W);
int k = randomIntBetween(MIN_K, MAX_K);
puzzle = randomPuzzle(h, w, k);
}
private void print() {
System.out.println("" + h + " " + w);
for (int i = 0; i < puzzle.length; i++)
System.out.println(puzzle[i]);
}
public static void main(String args[]) {
long seed = 1L;
if (args.length == 1)
seed = Long.parseLong(args[0]);
generator g = new generator();
g.generate(seed);
g.print();
}
}