/* -*- coding: utf-8 -*- * * 2947.cc: No.2947 Sing a Song - yukicoder */ #include #include #include using namespace std; /* constant */ const int MAX_N = 200000; const int MAX_L = 200000; /* typedef */ using ll = long long; /* global variables */ char s[MAX_L + 4], t[MAX_L + 4]; int as[MAX_N]; /* subroutines */ // exgcd: // For given x>0 and y>0, solve a, b, c such that ax+by=c (=gcd(x,y)) template void exgcd(T x, T y, T &a, T &b, T &c) { T r0 = x, r1 = y; T a0 = 1, a1 = 0; T b0 = 0, b1 = 1; while (r1 > 0) { T q1 = r0 / r1; T r2 = r0 % r1; T a2 = a0 - q1 * a1; T b2 = b0 - q1 * b1; r0 = r1, r1 = r2; a0 = a1, a1 = a2; b0 = b1, b1 = b2; } c = r0; a = a0; b = b0; } /* main */ int main() { int n; scanf("%d%s%s", &n, s, t); for (int i = 0; i < n; i++) scanf("%d", as + i); int x = strlen(s), y = strlen(t), a, b, g; exgcd(x, y, a, b, g); //printf(" %d*%d+%d*%d=%d\n", x, a, y, b, g); int da = y / g, db = x / g; for (int i = 0; i < n; i++) { int d = as[i] / g; int sa = a * d, tb = b * d; while (tb < 0) tb += db, sa -= da; while (tb >= db) tb -= db, sa += da; //printf(" %d,%d\n", sa, tb); for (int j = 0; j < sa; j++) printf("%s ", s); for (int j = 0; j < tb; j++) printf("%s ", t); putchar('\n'); } return 0; }