#include using namespace std; using ll = long long; // #define int ll // #define endl '\n' #define F first #define S second #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define sz(x) (int)(x).size() ll decode(vector const& a) { int n = sz(a)-2; int m = sz(a[0])-2; int y = 1, x = 0; while (a[y][x] == '.') x++; ll num = 1; while (y < n) { if (a[y+1][x+1] == '#') { num *= 2; x++; } else if (a[y+1][x-1] == '#') { num *= 2; num++; x--; } else assert(0); y++; } return num; } vector load() { int n; cin >> n; vector a(n+2); for (int i = 1; i <= n; i++) { string s; cin >> s; s = "." + s + "."; a[i] = s; } string border; for (int i = 0; i < sz(a[1]); i++) border.push_back('.'); a[0] = a[n+1] = border; return a; } vector encode(ll X) { int ops = 0; int mx_left = 0, mx_right = 0; int curr = 0; ll num = X; while (num != 1) { if (num % 2 == 0) { curr--; } else { curr++; } ops++; if (curr < 0) { mx_left = max(mx_left, abs(curr)); } else { mx_right = max(mx_right, curr); } num /= 2; } int n = ops+1; int m = 1 + mx_left+mx_right; vector res(n+2, string(m+2, '.')); int x = 1 + mx_left; int y = n; res[y][x] = '#'; while (X != 1) { if (X % 2 == 0) { x--; } else { x++; } y--; X /= 2; res[y][x] = '#'; } return res; } void tc() { // for (ll i = 1; i <= 100; i++) { // assert(decode(encode(i)) == i); // } auto a = load(); // cerr << decode(a) << endl; auto b = load(); // cerr << decode(b) << endl; auto e = encode(decode(a) + decode(b)); int n = sz(e)-2; int m = sz(e[0])-2; cout << n << endl; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cout << e[i][j]; } cout << endl; } } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); tc(); }