#include<cstdio> #define int long long #define re register constint MAXn = 10;
template <typename T> inline T qmul(T x, T y, T mod){ if (x == 0 || y == 0) return0; T ret = 0; while (y) { if (y & 1) ret = ((ret % mod) + (x % mod)) % mod; y >>= 1; x = ((x % mod) + (x % mod)) % mod; } return ret; }
intexgcd(int a, int b, int &x, int &y){ if (!b) { x = 1; y = 0; return a; } else { int d = exgcd(b, a % b, y, x); y -= a / b * x; return d; } }
intinv(int a, int m){ int k, inv; exgcd(a, m, inv, k); return (inv % m + m) % m; }
intcrt(int cnta, int *a, int *m){ int prod = 1, ans = 0; for (re int i = 1; i <= cnta; ++i) { prod *= m[i]; } for (re int i = 1, M; i <= cnta; ++i) { M = prod / m[i]; ans = (ans + qmul(qmul(a[i], M, prod), inv(M, m[i]), prod)) % prod; } return ans; }
int n, a[MAXn + 10], m[MAXn + 10]; signedmain(){ scanf("%lld", &n); for (re int i = 1; i <= n; ++i) { scanf("%lld", &a[i]); } for (re int i = 1; i <= n; ++i) { scanf("%lld", &m[i]); } printf("%lld\n", crt(n, a, m)); }