#pragma GCC optimize ("Ofast") #include using namespace std; #define MD 1000000007 #define PI 3.14159265358979323846 void *wmem; template inline S min_L(S a,T b){ return a<=b?a:b; } template inline S max_L(S a,T b){ return a>=b?a:b; } template inline void walloc1d(T **arr, int x, void **mem = &wmem){ static int skip[16]={0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] ); (*arr)=(T*)(*mem); (*mem)=((*arr)+x); } struct mint{ static unsigned R, RR, Rinv, W, md, mdninv; unsigned val; mint(){ } mint(int a){ val = mulR(a); } mint(unsigned a){ val = mulR(a); } mint(long long a){ val = mulR(a); } mint(unsigned long long a){ val = mulR(a); } int get_inv(long long a, int md){ long long e, s=md, t=a, u=1, v=0; while(s){ e=t/s; t-=e*s; u-=e*v; swap(t,s); swap(u,v); } if(u<0){ u+=md; } return u; } void setmod(unsigned m){ int i; unsigned t; W = 32; md = m; R = (1ULL << W) % md; RR = (unsigned long long)R*R % md; switch(m){ case 104857601: Rinv = 2560000; mdninv = 104857599; break; case 998244353: Rinv = 232013824; mdninv = 998244351; break; case 1000000007: Rinv = 518424770; mdninv = 2226617417U; break; case 1000000009: Rinv = 171601999; mdninv = 737024967; break; case 1004535809: Rinv = 234947584; mdninv = 1004535807; break; case 1007681537: Rinv = 236421376; mdninv = 1007681535; break; case 1012924417: Rinv = 238887936; mdninv = 1012924415; break; case 1045430273: Rinv = 254466304; mdninv = 1045430271; break; case 1051721729: Rinv = 257538304; mdninv = 1051721727; break; default: Rinv = get_inv(R, md); mdninv = 0; t = 0; for(i=0;i<((int)W);i++){ if(t%2==0){ t+=md; mdninv |= (1U<> W); if(t >= md){ t -= md; } return t; } unsigned reduce(unsigned long long T){ unsigned m=(unsigned)T * mdninv, t=(unsigned)((T + (unsigned long long)m*md) >> W); if(t >= md){ t -= md; } return t; } unsigned get(){ return reduce(val); } mint &operator+=(mint a){ val += a.val; if(val >= md){ val -= md; } return *this; } mint &operator-=(mint a){ if(val < a.val){ val = val + md - a.val; } else{ val -= a.val; } return *this; } mint &operator*=(mint a){ val = reduce((unsigned long long)val*a.val); return *this; } mint &operator/=(mint a){ return *this *= a.inverse(); } mint operator+(mint a){ return mint(*this)+=a; } mint operator-(mint a){ return mint(*this)-=a; } mint operator*(mint a){ return mint(*this)*=a; } mint operator/(mint a){ return mint(*this)/=a; } mint operator+(int a){ return mint(*this)+=mint(a); } mint operator-(int a){ return mint(*this)-=mint(a); } mint operator*(int a){ return mint(*this)*=mint(a); } mint operator/(int a){ return mint(*this)/=mint(a); } mint operator+(long long a){ return mint(*this)+=mint(a); } mint operator-(long long a){ return mint(*this)-=mint(a); } mint operator*(long long a){ return mint(*this)*=mint(a); } mint operator/(long long a){ return mint(*this)/=mint(a); } mint operator-(void){ mint res; if(val){ res.val=md-val; } else{ res.val=0; } return res; } operator bool(void){ return val!=0; } operator int(void){ return get(); } operator long long(void){ return get(); } mint inverse(){ int a=val, b=md, t, u=1, v=0; mint res; while(b){ t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } if(u < 0){ u += md; } res.val = (unsigned long long)u*RR % md; return res; } mint pw(unsigned long long b){ mint a(*this), res; res.val = R; while(b){ if(b&1){ res *= a; } b >>= 1; a *= a; } return res; } bool operator==(int a){ return mulR(a)==val; } bool operator!=(int a){ return mulR(a)!=val; } } ; mint operator+(int a, mint b){ return mint(a)+=b; } mint operator-(int a, mint b){ return mint(a)-=b; } mint operator*(int a, mint b){ return mint(a)*=b; } mint operator/(int a, mint b){ return mint(a)/=b; } mint operator+(long long a, mint b){ return mint(a)+=b; } mint operator-(long long a, mint b){ return mint(a)-=b; } mint operator*(long long a, mint b){ return mint(a)*=b; } mint operator/(long long a, mint b){ return mint(a)/=b; } inline void rd(int &x){ int k, m=0; x=0; for(;;){ k = getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline void wt_L(char a){ putchar_unlocked(a); } inline void wt_L(int x){ char f[10]; int m=0, s=0; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ putchar_unlocked('-'); } while(s--){ putchar_unlocked(f[s]+'0'); } } inline void wt_L(mint x){ int i; i = (int)x; wt_L(i); } template inline T pow_L(T a, S b){ T res=1; res = 1; while(b){ if(b&1){ res *= a; } b >>= 1; a *= a; } return res; } struct fft_pnt{ double x, y; fft_pnt(void){ } fft_pnt(double a, double b){ x = a; y = b; } void set(double a, double b){ x = a; y = b; } fft_pnt& operator+=(fft_pnt a){ x+=a.x; y+=a.y; return *this; } fft_pnt& operator-=(fft_pnt a){ x-=a.x; y-=a.y; return *this; } fft_pnt& operator*=(fft_pnt a){ fft_pnt p=*this; x = p.x*a.x-p.y*a.y; y = p.x*a.y+p.y*a.x; return *this; } fft_pnt operator+(fft_pnt a){ return fft_pnt(*this) += a; } fft_pnt operator-(fft_pnt a){ return fft_pnt(*this) -= a; } fft_pnt operator*(fft_pnt a){ return fft_pnt(*this) *= a; } } ; void fft_L(int n, fft_pnt x[], void *mem){ double theta=2*PI / n, tmp; fft_pnt a, aa, b, bb, c, cc, d, dd, w1, w2, w3, *y=(fft_pnt*)mem; int i, j, n1, n2, n3, step=1; while(n > 2){ n1 = n / 4; n2 = n1 + n1; n3 = n1 + n2; for(i=0;i<(n1);i++){ w1 = fft_pnt(cos(i*theta),-sin(i*theta)); w2 = w1*w1; w3 = w1*w2; for(j=0;j<(step);j++){ a = x[j+step*i]; b = x[j+step*(i+n1)]; c = x[j+step*(i+n2)]; d = x[j+step*(i+n3)]; aa = a + c; bb = a - c; cc = b + d; dd = b - d; tmp = dd.y; dd.y = dd.x; dd.x = -tmp; y[j+step*(4*i )] = aa + cc; y[j+step*(4*i+1)] = w1*(bb - dd); y[j+step*(4*i+2)] = w2*(aa - cc); y[j+step*(4*i+3)] = w3*(bb + dd); } } n /= 4; step *= 4; theta *= 4; swap(x,y); } if(n==2){ for(i=0;i<(step);i++){ y[i] = x[i] + x[i+step]; y[i+step] = x[i] - x[i+step]; } n /= 2; step *= 2; theta *= 2; swap(x,y); } for(i=0;i<(step);i++){ y[i] = x[i]; } } void fftinv_L(int n, fft_pnt x[], void *mem){ double theta=2*PI / n, tmp; fft_pnt a, aa, b, bb, c, cc, d, dd, w1, w2, w3, *y=(fft_pnt*)mem; int i, j, n1, n2, n3, step=1; while(n > 2){ n1 = n / 4; n2 = n1 + n1; n3 = n1 + n2; for(i=0;i<(n1);i++){ w1 = fft_pnt(cos(i*theta),sin(i*theta)); w2 = w1*w1; w3 = w1*w2; for(j=0;j<(step);j++){ a = x[j+step*i]; b = x[j+step*(i+n1)]; c = x[j+step*(i+n2)]; d = x[j+step*(i+n3)]; aa = a + c; bb = a - c; cc = b + d; dd = b - d; tmp = dd.y; dd.y = dd.x; dd.x = -tmp; y[j+step*(4*i )] = aa + cc; y[j+step*(4*i+1)] = w1*(bb + dd); y[j+step*(4*i+2)] = w2*(aa - cc); y[j+step*(4*i+3)] = w3*(bb - dd); } } n /= 4; step *= 4; theta *= 4; swap(x,y); } if(n==2){ for(i=0;i<(step);i++){ y[i] = x[i] + x[i+step]; y[i+step] = x[i] - x[i+step]; } n /= 2; step *= 2; theta *= 2; swap(x,y); } for(i=0;i<(step);i++){ y[i] = x[i]; } } void convolution_L(double A[], int As, double B[], int Bs, double res[], int Rs, void *mem = wmem){ double mul; fft_pnt *a, *b; int i, n, n2; n =max_L(As+Bs, Rs); for(n2=1;n2=0;i--){ s[i] = s[i+1] + A[i]; } for(i=0;i<(N);i++){ res *= (pow_L(mint(A[i]),s[i+1])); } mn[N] = 1073709056; for(i=N-1;i>=0;i--){ mn[i] =min_L(mn[i+1], A[i]); } dmin = 1e300; for(i=N-2;i>=0;i--){ dtmp = log(A[i] + mn[i+1]) + log(A[i]) * mn[i+1]; if(dtmp < dmin){ dmin = dtmp; tmp = (A[i] + mn[i+1]) * (pow_L(mint(A[i]),mn[i+1])); } } res /= tmp; wt_L(res); wt_L('\n'); return 0; } // cLay varsion 20190820-1 // --- original code --- // int N, A[1d5]; // // double c[100001], cnv[200001]; // ll s[100001]; // int mn[100001]; // { // int i; // ll tk; // mint res, tmp; // double dmin, dtmp; // // rd(N,A(N)); // // res = 1; // // rep(i,N) c[A[i]]++; // convolution(c, 100001, cnv, 200001); // rep(i,N) cnv[2A[i]]--; // // rep(i,200001){ // tk = (ll)(cnv[i]/2 + 0.5); // if(tk) res *= (mint(i) ** tk); // } // // for(i=N-1;i>=0;i--) s[i] = s[i+1] + A[i]; // rep(i,N) res *= (mint(A[i]) ** s[i+1]); // // mn[N] = int_inf; // for(i=N-1;i>=0;i--) mn[i] = min(mn[i+1], A[i]); // // dmin = 1e300; // for(i=N-2;i>=0;i--){ // dtmp = log(A[i] + mn[i+1]) + log(A[i]) * mn[i+1]; // if(dtmp < dmin){ // dmin = dtmp; // tmp = (A[i] + mn[i+1]) * ( mint(A[i]) ** mn[i+1] ); // } // } // // res /= tmp; // wt(res); // }