#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
const int mod = 1e9 + 7;
int n, curx = 1, x[1 << 19], y[1 << 19], curinv;
long double rcurx = 0, rcurinv;
struct node {
int val = 1, lazy = 1;
long double rval, rlazy;
} st[1 << 20];
void Build(int node = 1, int left = 1, int right = n) {
if (left == right) {
curx = 1LL * curx * x[left - 1] % mod;
st[node].val = 1LL * curx * y[left - 1] % mod;
rcurx += log10(x[left - 1]);
st[node].rval = rcurx + log10(y[left - 1]);
return;
}
int m = (left + right) / 2;
Build(2 * node, left, m), Build(2 * node + 1, m + 1, right);
if (st[2 * node].rval > st[2 * node + 1].rval)
st[node].rval = st[2 * node].rval, st[node].val = st[2 * node].val;
else
st[node].rval = st[2 * node + 1].rval, st[node].val = st[2 * node + 1].val;
}
void Propagate(int node, int left, int right) {
if (st[node].lazy == 1)
return;
st[node].val = 1LL * st[node].val * st[node].lazy % mod;
st[node].rval += st[node].rlazy;
if (left != right) {
st[2 * node].lazy = 1LL * st[2 * node].lazy * st[node].lazy % mod, st[2 * node].rlazy += st[node].rlazy;
st[2 * node + 1].lazy = 1LL * st[2 * node + 1].lazy * st[node].lazy % mod, st[2 * node + 1].rlazy += st[node].rlazy;
}
st[node].lazy = 1, st[node].rlazy = 0;
}
void Update(int val, long double rval, int posleft, int posright = n, int node = 1, int left = 1, int right = n) {
if (posleft <= left && right <= posright) {
st[node].lazy = 1LL * st[node].lazy * val % mod;
st[node].rlazy += rval;
Propagate(node, left, right);
return;
}
Propagate(node, left, right);
int m = (left + right) / 2;
if (posleft <= m)
Update(val, rval, posleft, posright, 2 * node, left, m), Propagate(2 * node + 1, m + 1, right);
if (posright > m)
Update(val, rval, posleft, posright, 2 * node + 1, m + 1, right), Propagate(2 * node, left, m);
if (st[2 * node].rval > st[2 * node + 1].rval)
st[node].rval = st[2 * node].rval, st[node].val = st[2 * node].val;
else
st[node].rval = st[2 * node + 1].rval, st[node].val = st[2 * node + 1].val;
}
int pow(int b, int e) {
int ans = 1;
while (e) {
if (e & 1)
ans = 1LL * ans * b % mod;
b = 1LL * b * b % mod, e >>= 1;
}
return ans;
}
int id = 0;
int init(int N, int X[], int Y[]) {
n = N;
for (int i = 0; i < n; ++i)
x[i] = X[i], y[i] = Y[i];
Build();
return st[1].val;
}
int updateX(int pos, int val) {
Update(1LL * val * pow(x[pos], mod - 2) % mod, -log(x[pos]) + log(val), pos + 1);
x[pos] = val;
return st[1].val;
}
int updateY(int pos, int val) {
Update(1LL * val * pow(y[pos], mod - 2) % mod, -log(y[pos] + log(val)), pos + 1, pos + 1);
y[pos] = val;
return st[1].val;
}