#include #include using namespace std; using i64 = long long; i64 load_number() { i64 num = 1; int ops; cin >> ops; int lastIndex = 0; string first; getline(cin, first); getline(cin, first); for (int j = 0; j < first.length(); j++) { if (first[j] == '.') { continue; } lastIndex = j; break; } for (int i = 1; i < ops; i++) { string line; getline(cin, line); if (lastIndex > 0 && line[lastIndex - 1] == '#') { num = num * 2 + 1; lastIndex = lastIndex - 1; } else { num = num * 2; lastIndex = lastIndex + 1; } } return num; } int main() { cin.tie(NULL); std::ios::sync_with_stdio(false); i64 first = load_number(); i64 second = load_number(); i64 result = first + second; i64 t = result; int rows = 1; int current = 0, left = 0, right = 0; while (t > 1) { if (t % 2 == 0) { current -= 1; left = min(left, current); } else { current += 1; right = max(right, current); } t /= 2; rows += 1; } int bitCount = right - left + 1; int position = abs(left); char* chars = (char*) calloc(rows, bitCount); chars[bitCount * (rows - 1) + position] = '#'; for (int i = rows - 2; i >= 0; i--) { if (result % 2 == 0) { chars[i * bitCount + position - 1] = '#'; position -= 1; } else { chars[i * bitCount + position + 1] = '#'; position += 1; } result /= 2; } cout << rows << '\n'; for (int i = 0; i < rows; i++) { char* string = new char[bitCount + 1]; for (int j = 0; j < bitCount; j++) { string[j] = chars[i * bitCount + j] == '#' ? '#' : '.'; } string[bitCount] = '\0'; cout << string << '\n'; delete[] string; } free(chars); return 0; }