#pragma GCC optimize("O3") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; using T = tuple; template inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;} template inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;} constexpr int MOD = 1e9 + 7; constexpr int inf = 1e9; constexpr long long INF = 1e18; #define all(a) (a).begin(), (a).end() int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; // refer to http://beet-aizu.hatenablog.com/entry/2019/03/12/171221 template struct SegmentTree{ int n; F f; G g; T ti; vector dat; SegmentTree(){}; SegmentTree(F f, G g, T ti) : f(f), g(g), ti(ti){} void init(int n_){ n = 1; while(n < n_) n <<= 1; dat.assign(n << 1, ti); } void build(const vector &v){ int sz = v.size(); init(sz); for(int i=0; i=0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } void set_val(int k, T x){ k += n; dat[k] = g(dat[k], x); while(k >>= 1) dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]); } T query(int a,int b){ T vl = ti, vr = ti; for(int l=a+n,r=b+n;l>=1,r>>=1) { if(l & 1) vl = f(vl, dat[l++]); if(r & 1) vr = f(dat[--r], vr); } return f(vl, vr); } }; int main(){ cin.tie(0); ios::sync_with_stdio(false); using T = ll; using E = ll; auto f = [](T a, T b){ return __gcd(a, b); }; auto g = [](T a, E b){ return b; }; T ti = 0; SegmentTree seg(f, g, ti); int n; cin>>n; vector a(n); for(int i=0; i>a[i]; seg.build(vector(n, 0)); for(int i=0; i