#include <stdio.h>
#define INPUT_FILE "interclasm.in"
#define OUTPUT_FILE "interclasm.out"
#define MAX_LEN 1000000
int main() {
int x;
int n;
int m;
int dp[MAX_LEN];
int foo;
for (int i = 0; i <= MAX_LEN; i++) {
dp[i] = 0;
}
FILE* fd_input = fopen(INPUT_FILE, "rt");
FILE* fd_output = fopen(OUTPUT_FILE, "wt");
// Citirea datelor din fisier
fscanf(fd_input, "%d %d", &x, &n);
for (int i = 0; i < n; i++) {
fscanf(fd_input, "%d", &foo);
dp[foo]++;
}
fscanf(fd_input, "%d", &m);
for (int i = 0; i < m; i++) {
fscanf(fd_input, "%d", &foo);
dp[foo]++;
}
// Afisez doar multiplii unici
for (int i = 1; i < MAX_LEN; i++) {
if (dp[i] == 1 && i % x == 0) {
fprintf(fd_output, "%d ", i);
}
}
fclose(fd_input);
fclose(fd_output);
return 0;
}