#include #include #include #include using namespace std; const int mod = 998244353; void add(int& u, int v) { u += v; if (u >= mod) u -= mod; } void sub(int& u, int v) { u -= v; if (u < 0) u += mod; } int power(int a, int b) { int res = 1; while (b) { if (b % 2) res = res * 1ll * a % mod; a = a * 1ll * a % mod; b /= 2; } return res; } int main() { int n, x, y; scanf("%d%d%d", &n, &x, &y); vector a(x); vector b(y); for (int i = 0; i < x; i++) scanf("%lld", &a[i]); for (int i = 0; i < y; i++) scanf("%lld", &b[i]); int ans = 0; for (int it = 0; it <= 60; it++) { long long bit = 1ll << it; int a0 = 0, a1 = 0; int b0 = 0, b1 = 0; for (int i = 0; i < x; i++) { if (a[i] & bit) a1++; else a0++; } for (int i = 0; i < y; i++) { if (b[i] & bit) b1++; else b0++; } for (int fst = 1; fst <= n; fst++) { int way = power(a0 + a1, fst - 1) * 1ll * power(a0, n - fst) % mod * 1ll * a1 % mod; int mul = power(b0 + b1, fst - 1) * 1ll * power(b1, n - fst + 1) % mod; int conb = bit % mod * 1ll * way % mod * 1ll * mul % mod; add(ans, conb); } } printf("%d\n", ans); return 0; }