#include using namespace std; typedef long long int ll; int gcd(int a, int b){ return b ? gcd(b,a%b) : a; } void build(int s, int e, int at, vector &arr, vector> &sg){ if(s>=e){ sg[at]=make_pair(abs(arr[s]),arr[s]); }else{ int m=(s+e)>>1; build(s,m,at*2+1,arr,sg); build(m+1,e,at*2+2,arr,sg); sg[at].first = gcd(abs(sg[at*2+1].first),abs(sg[at*2+2].first)); sg[at].second = max(sg[at*2+1].second,sg[at*2+2].second); } } pair query(int s, int e, int at, int l, int r, vector> &sg){ if(l<=s && e<=r) return sg[at]; int m=(s+e)>>1; if(r<=m) return query(s,m,at*2+1,l,r,sg); if(l>=m) return query(m+1,e,at*2+2,l,r,sg); auto p1 = query(s,m,at*2+1,l,m,sg); auto p2 = query(m+1,e,at*2+2,m+1,r,sg); auto f=gcd(abs(p1.first),abs(p2.first)); auto sc=max(p1.second,p2.second); return make_pair(f,sc); } int main(){ int n; cin>>n; vector arr(n); for(int i=0; i>arr[i]; int k = ceil(log2(n))+2; k=(1<> sg(k); build(0,n-1,0,arr,sg); vector sum(n+1,0); for(int i=0; i