#include #include #include #include using namespace std; // 拡張ユークリッドの互除法 int ExtGCD(int a, int b, int &x, int &y) { if (b == 0) { x = 1; y = 0; return a; } int d = ExtGCD(b, a % b, y, x); y -= (a / b) * x; return d; } int main() { int N; cin >> N; string S, T; cin >> S >> T; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } int s = S.size(), t = T.size(); if (s == t) { for (int i = 0; i < N; i++) { for (int j = 0; j < A[i] / s; j++) { cout << S << " "; } cout << endl; } } else { int g, x, y; g = ExtGCD(s, t, x, y); int p = s / g; for (int i = 0; i < N; i++) { int n = A[i] * y / p; int a = A[i] / g * x + t / g * n; int b = A[i] / g * y - s / g * n; for (int j = 0; j < a; j++) { cout << S << " "; } for (int j = 0; j < b; j++) { cout << T << " "; } cout << endl; } } return 0; }