#include <bits/stdc++.h>
#include "horses.h"
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 5e5 + 2;
const int mod = 1e9 + 7;
int Mul(int a, int b) {
ll c = a; c *= b; c %= mod;
return c;
}
int Exp(int a, int b) {
int ans = 1;
while (b > 0) {
if (b & 1) ans = Mul(ans, a);
a = Mul(a, a);
b >>= 1;
}
return ans;
}
int Div(int a, int b) {
return Mul(a, Exp(b, mod - 2));
}
struct Node {
ld mx, lzymx;
int f, lzyf;
}st[4 * N];
int n, x[N], y[N], prod[N];
double sum[N];
void Pull(int node) {
if (st[2 * node].mx > st[2 * node + 1].mx) st[node] = st[2 * node];
else st[node] = st[2 * node + 1];
}
void Build(int node, int l, int r) {
if (l == r) {
st[node].mx = sum[l] + log10l(y[l]); st[node].lzymx = 0;
st[node].f = Mul(prod[l], y[l]); st[node].lzyf = 1;
return;
}
int mid = l + r >> 1;
Build(2 * node, l, mid);
Build(2 * node + 1, mid + 1, r);
Pull(node);
}
void Push(int node, int l, int r) {
if (st[node].lzymx == 0) return;
if (l < r) {
st[2 * node].lzymx += st[node].lzymx;
st[2 * node].lzyf = Mul(st[2 * node].lzyf, st[node].lzyf);
st[2 * node + 1].lzymx += st[node].lzymx;
st[2 * node + 1].lzyf = Mul(st[2 * node + 1].lzyf, st[node].lzyf);
}
st[node].mx += st[node].lzymx;
st[node].f = Mul(st[node].f, st[node].lzyf);
st[node].lzymx = 0;
st[node].lzyf = 1;
}
int init(int N, int X[], int Y[]) {
n = N;
sum[0] = 0;
prod[0] = 1;
for (int i = 1; i <= n; i++) {
x[i] = X[i - 1];
y[i] = Y[i - 1];
sum[i] = sum[i - 1] + log10l(x[i]);
prod[i] = Mul(prod[i - 1], x[i]);
}
Build(1, 1, n);
return st[1].f;
}
void Update(int node, int l, int r, int ql, int qr, ld x, int y) {
Push(node, l, r);
if (r < ql || qr < l) return;
if (ql <= l && r <= qr) {
st[node].lzymx += x;
st[node].lzyf = Mul(st[node].lzyf, y);
Push(node, l, r);
return;
}
int mid = l + r >> 1;
Update(2 * node, l, mid, ql, qr, x, y);
Update(2 * node + 1, mid + 1, r, ql, qr, x, y);
Pull(node);
}
int updateX(int pos, int val) {
pos += 1;
Update(1, 1, n, pos, n, log10l(val) - log10l(x[pos]), Div(val, x[pos]));
x[pos] = val;
return st[1].f;
}
int updateY(int pos, int val) {
pos += 1;
Update(1, 1, n, pos, pos, log10l(val) - log10l(y[pos]), Div(val, y[pos]));
y[pos] = val;
return st[1].f;
}