#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
static const ll MOD = 1000000007LL;
struct Big {
static const uint32_t BASE = 1000000000U;
vector<uint32_t> d; // little-endian
Big(uint64_t v = 0) { *this = v; }
Big& operator=(uint64_t v) {
d.clear();
if (v == 0) return *this;
while (v > 0) {
d.push_back((uint32_t)(v % BASE));
v /= BASE;
}
return *this;
}
bool empty() const { return d.empty(); }
void trim() {
while (!d.empty() && d.back() == 0) d.pop_back();
}
void mul_small(uint64_t m) {
if (m == 0 || d.empty()) {
d.clear();
return;
}
__uint128_t carry = 0;
for (size_t i = 0; i < d.size(); ++i) {
__uint128_t cur = (__uint128_t)d[i] * m + carry;
d[i] = (uint32_t)(cur % BASE);
carry = cur / BASE;
}
while (carry > 0) {
d.push_back((uint32_t)(carry % BASE));
carry /= BASE;
}
}
int cmp(const Big& other) const {
if (d.size() != other.d.size()) {
return d.size() < other.d.size() ? -1 : 1;
}
for (int i = (int)d.size() - 1; i >= 0; --i) {
if (d[i] != other.d[i]) {
return d[i] < other.d[i] ? -1 : 1;
}
}
return 0;
}
bool operator<(const Big& other) const { return cmp(other) < 0; }
bool operator>(const Big& other) const { return cmp(other) > 0; }
bool operator==(const Big& other) const { return cmp(other) == 0; }
};
vector<ll> x, y;
static int calc() {
int N = (int)x.size();
Big pref(1), best(0), cur;
ll prefMod = 1, bestMod = 0;
for (int i = 0; i < N; ++i) {
pref.mul_small((uint64_t)x[i]);
prefMod = (ll)((__int128)prefMod * x[i] % MOD);
cur = pref;
cur.mul_small((uint64_t)y[i]);
ll curMod = (ll)((__int128)prefMod * y[i] % MOD);
if (cur > best) {
best = cur;
bestMod = curMod;
}
}
return (int)bestMod;
}
int init(int N, int X[], int Y[]) {
x.assign(X, X + N);
y.assign(Y, Y + N);
return calc();
}
int updateX(int pos, int val) {
x[pos] = val;
return calc();
}
int updateY(int pos, int val) {
y[pos] = val;
return calc();
}