結果

問題 No.856 増える演算
ユーザー LayCurseLayCurse
提出日時 2019-07-26 23:30:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 3,153 ms
コード長 14,327 bytes
コンパイル時間 2,479 ms
コンパイル使用メモリ 210,356 KB
実行使用メモリ 17,868 KB
最終ジャッジ日時 2024-07-02 09:59:51
合計ジャッジ時間 7,025 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
14,792 KB
testcase_01 AC 22 ms
15,564 KB
testcase_02 AC 21 ms
14,668 KB
testcase_03 AC 22 ms
15,440 KB
testcase_04 AC 21 ms
15,440 KB
testcase_05 AC 22 ms
16,208 KB
testcase_06 AC 22 ms
15,568 KB
testcase_07 AC 21 ms
16,200 KB
testcase_08 AC 21 ms
15,952 KB
testcase_09 AC 23 ms
14,792 KB
testcase_10 AC 22 ms
15,568 KB
testcase_11 AC 20 ms
14,664 KB
testcase_12 AC 21 ms
15,444 KB
testcase_13 AC 22 ms
15,580 KB
testcase_14 AC 21 ms
16,072 KB
testcase_15 AC 21 ms
15,948 KB
testcase_16 AC 22 ms
15,576 KB
testcase_17 AC 21 ms
14,664 KB
testcase_18 AC 21 ms
15,576 KB
testcase_19 AC 23 ms
15,452 KB
testcase_20 AC 22 ms
15,576 KB
testcase_21 AC 20 ms
15,576 KB
testcase_22 AC 20 ms
14,800 KB
testcase_23 AC 23 ms
15,436 KB
testcase_24 AC 24 ms
15,700 KB
testcase_25 AC 22 ms
15,572 KB
testcase_26 AC 21 ms
15,948 KB
testcase_27 AC 22 ms
15,568 KB
testcase_28 AC 24 ms
15,568 KB
testcase_29 AC 23 ms
15,436 KB
testcase_30 AC 23 ms
16,072 KB
testcase_31 AC 22 ms
15,444 KB
testcase_32 AC 24 ms
14,792 KB
testcase_33 AC 25 ms
15,700 KB
testcase_34 AC 28 ms
15,700 KB
testcase_35 AC 26 ms
15,704 KB
testcase_36 AC 28 ms
16,080 KB
testcase_37 AC 27 ms
14,920 KB
testcase_38 AC 21 ms
15,952 KB
testcase_39 AC 23 ms
15,448 KB
testcase_40 AC 25 ms
15,576 KB
testcase_41 AC 25 ms
15,580 KB
testcase_42 AC 27 ms
16,208 KB
testcase_43 AC 24 ms
15,704 KB
testcase_44 AC 21 ms
15,948 KB
testcase_45 AC 23 ms
15,704 KB
testcase_46 AC 25 ms
14,796 KB
testcase_47 AC 23 ms
15,576 KB
testcase_48 AC 25 ms
14,928 KB
testcase_49 AC 25 ms
15,576 KB
testcase_50 AC 26 ms
15,836 KB
testcase_51 AC 27 ms
15,176 KB
testcase_52 AC 28 ms
15,832 KB
testcase_53 AC 56 ms
16,072 KB
testcase_54 AC 44 ms
16,200 KB
testcase_55 AC 52 ms
16,576 KB
testcase_56 AC 40 ms
15,180 KB
testcase_57 AC 53 ms
16,488 KB
testcase_58 AC 52 ms
15,948 KB
testcase_59 AC 63 ms
16,484 KB
testcase_60 AC 48 ms
16,000 KB
testcase_61 AC 62 ms
16,332 KB
testcase_62 AC 59 ms
15,568 KB
testcase_63 AC 27 ms
15,692 KB
testcase_64 AC 59 ms
15,436 KB
testcase_65 AC 38 ms
16,308 KB
testcase_66 AC 48 ms
15,932 KB
testcase_67 AC 51 ms
16,076 KB
testcase_68 AC 58 ms
16,072 KB
testcase_69 AC 59 ms
16,380 KB
testcase_70 AC 66 ms
17,140 KB
testcase_71 AC 59 ms
16,456 KB
testcase_72 AC 57 ms
16,268 KB
testcase_73 AC 68 ms
17,252 KB
testcase_74 AC 68 ms
16,208 KB
testcase_75 AC 68 ms
17,868 KB
testcase_76 AC 68 ms
16,336 KB
testcase_77 AC 65 ms
16,332 KB
testcase_78 AC 67 ms
16,208 KB
testcase_79 AC 70 ms
17,268 KB
testcase_80 AC 72 ms
15,688 KB
testcase_81 AC 73 ms
16,460 KB
testcase_82 AC 48 ms
15,948 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
In member function 'mint mint::inverse()',
    inlined from 'mint& mint::operator/=(mint)' at main.cpp:160:31,
    inlined from 'int main()' at main.cpp:627:10:
main.cpp:218:11: warning: 'tmp.mint::val' may be used uninitialized [-Wmaybe-uninitialized]
  218 |     int a=val, b=md, t, u=1, v=0;
      |           ^~~
main.cpp: In function 'int main()':
main.cpp:580:13: note: 'tmp.mint::val' was declared here
  580 |   mint res, tmp;
      |             ^~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define MD 1000000007
void *wmem;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
template<class T> void walloc1d(T **arr, int x, void **mem = &wmem){
  (*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<<i);
        }
        t /= 2;
      }
    }
  }
  unsigned mulR(unsigned a){
    return (unsigned long long)a*R%md;
  }
  unsigned mulR(int a){
    if(a < 0){
      a = a%md+md;
    }
    return mulR((unsigned)a);
  }
  unsigned mulR(unsigned long long a){
    return mulR((unsigned)(a%md));
  }
  unsigned mulR(long long a){
    a %= md;
    if(a < 0){
      a += md;
    }
    return mulR((unsigned)a);
  }
  unsigned reduce(unsigned T){
    unsigned m=T * mdninv, t=(unsigned)((T + (unsigned long long)m*md) >> 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<class T, class S> 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;
}
char memarr[96000000];
unsigned mint::R, mint::RR, mint::Rinv, mint::W, mint::md, mint::mdninv;
#define PI 3.141592653589793238462
struct pnt{
  double x, y;
  static double eps;
  pnt(void){
  }
  pnt(double a,double b){
    x=a;
    y=b;
  }
  void set(double a,double b){
    x=a;
    y=b;
  }
  pnt&operator+=(pnt a){
    x+=a.x;
    y+=a.y;
    return*this;
  }
  pnt&operator-=(pnt a){
    x-=a.x;
    y-=a.y;
    return*this;
  }
  pnt&operator*=(pnt a){
    pnt p=*this;
    x=p.x*a.x-p.y*a.y;
    y=p.x*a.y+p.y*a.x;
    return*this;
  }
  pnt operator+(pnt a){
    return pnt(*this)+=a;
  }
  pnt operator-(pnt a){
    return pnt(*this)-=a;
  }
  pnt operator*(pnt a){
    return pnt(*this)*=a;
  }
}
;
double pnt::eps = 1e-10;
unsigned long long pw(unsigned long long a, unsigned long long b, unsigned long long m){
  unsigned long long r=1;
  while(b){
    if(b&1){
      r=r*a%m;
    }
    b>>=1;
    a=a*a%m;
  }
  return r;
}
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 fft(int n, pnt x[], void *mem){
  double p, t=2*PI/n;
  int I, J, K, i, j, s=1;
  pnt A, B, C, D, a, b, c, d, u, v, w, *y=(pnt*)mem;
  while(n>2){
    I=n/4;
    J=I+I;
    K=I+J;
    for(i=0;i<I;i++){
      w=pnt(cos(i*t),-sin(i*t));
      v=w*w;
      u=w*v;
      for(j=0;j<s;j++){
        a=x[j+s*i];
        b=x[j+s*(i+I)];
        c=x[j+s*(i+J)];
        d=x[j+s*(i+K)];
        A=a+c;
        B=a-c;
        C=b+d;
        D=b-d;
        p=D.y;
        D.y=D.x;
        D.x=-p;
        y[j+s*4*i]=A+C;
        y[j+s*(4*i+1)]=w*(B-D);
        y[j+s*(4*i+2)]=v*(A-C);
        y[j+s*(4*i+3)]=u*(B+D);
      }
    }
    n/=4;
    s*=4;
    t*=4;
    swap(x,y);
  }
  if(n==2){
    for(i=0;i<s;i++){
      y[i]=x[i]+x[i+s];
      y[i+s]=x[i]-x[i+s];
    }
    n/=2;
    s*=2;
    t*=2;
    swap(x,y);
  }
  for(i=0;i<s;i++){
    y[i]=x[i];
  }
}
void fftinv(int n, pnt x[], void *mem){
  double p, t=2*PI/n;
  int I, J, K, i, j, s=1;
  pnt A, B, C, D, a, b, c, d, u, v, w, *y=(pnt*)mem;
  while(n>2){
    I=n/4;
    J=I+I;
    K=I+J;
    for(i=0;i<I;i++){
      w=pnt(cos(i*t),sin(i*t));
      v=w*w;
      u=w*v;
      for(j=0;j<s;j++){
        a=x[j+s*i];
        b=x[j+s*(i+I)];
        c=x[j+s*(i+J)];
        d=x[j+s*(i+K)];
        A=a+c;
        B=a-c;
        C=b+d;
        D=b-d;
        p=D.y;
        D.y=D.x;
        D.x=-p;
        y[j+s*4*i]=A+C;
        y[j+s*(4*i+1)]=w*(B+D);
        y[j+s*(4*i+2)]=v*(A-C);
        y[j+s*(4*i+3)]=u*(B-D);
      }
    }
    n/=4;
    s*=4;
    t*=4;
    swap(x,y);
  }
  if(n==2){
    for(i=0;i<s;i++){
      y[i]=x[i]+x[i+s];
      y[i+s]=x[i]-x[i+s];
    }
    n/=2;
    s*=2;
    t*=2;
    swap(x,y);
  }
  for(i=0;i<s;i++){
    y[i]=x[i];
  }
}
void convolution(double A[], int As, double B[], int Bs, double res[], int Rs, void *mem){
  double m;
  int i, k, n;
  pnt *a, *b;
  n=max_L(As+Bs, Rs);
  for(k=1;k<n;k*=2){
    ;
  }
  a=(pnt*)mem;
  b=a+k;
  mem=b+k;
  for(i=0;i<As;i++){
    a[i].set(A[i],0);
  }
  for(i=As;i<k;i++){
    a[i].set(0,0);
  }
  for(i=0;i<Bs;i++){
    b[i].set(B[i],0);
  }
  for(i=Bs;i<k;i++){
    b[i].set(0,0);
  }
  fft(k,a,mem);
  fft(k,b,mem);
  for(i=0;i<k;i++){
    a[i]*=b[i];
  }
  fftinv(k,a,mem);
  m=1.0/k;
  for(i=0;i<Rs;i++){
    res[i]=a[i].x*m;
  }
}
void convolution(double A[], int As, double res[], int Rs, void *mem){
  double m;
  int i, k, n;
  pnt *a;
  n=max_L(As+As, Rs);
  for(k=1;k<n;k*=2){
    ;
  }
  a=(pnt*)mem;
  mem=a+k;
  for(i=0;i<As;i++){
    a[i].set(A[i],0);
  }
  for(i=As;i<k;i++){
    a[i].set(0,0);
  }
  fft(k,a,mem);
  for(i=0;i<k;i++){
    a[i]*=a[i];
  }
  fftinv(k,a,mem);
  m=1.0/k;
  for(i=0;i<Rs;i++){
    res[i]=a[i].x*m;
  }
}
int N;
int A[100000];
double c[100001];
double cnv[200001];
long long s[100001];
int mn[100001];
int main(){
  double dmin, dtmp;
  int *ddd, i, j, k;
  long long tk;
  mint res, tmp;
  wmem = memarr;
  {
    mint x;
    x.setmod(MD);
  }
  walloc1d(&ddd,1);
  rd(N);
  {
    int Q5VJL1cS;
    for(Q5VJL1cS=0;Q5VJL1cS<N;Q5VJL1cS++){
      rd(A[Q5VJL1cS]);
    }
  }
  res = 1;
  for(i=0;i<N;i++){
    c[A[i]]++;
  }
  convolution(c, 100001, cnv, 200001, wmem);
  for(i=0;i<N;i++){
    cnv[2*A[i]]--;
  }
  for(i=0;i<200001;i++){
    tk = (long long)(cnv[i]/2 + 0.5);
    if(tk){
      res *= (pow_L(mint(i),tk));
    }
  }
  for(i=N-1;i>=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];
      tmp *=pow_L(mint(A[i]),mn[i+1]);
    }
  }
  res /= tmp;
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// #define PI 3.141592653589793238462
// struct pnt{double x,y;static double eps;pnt(void){}pnt(double a,double b){x=a;y=b;}void set(double a,double b){x=a;y=b;}pnt&operator+=(pnt a){x+=a.x;y+=a.y;return*this;}pnt&operator-=(pnt a){x-=a.x;y-=a.y;return*this;}pnt&operator*=(pnt a){pnt p=*this;x=p.x*a.x-p.y*a.y;y=p.x*a.y+p.y*a.x;return*this;}pnt operator+(pnt a){return pnt(*this)+=a;}pnt operator-(pnt a){return pnt(*this)-=a;}pnt operator*(pnt a){return pnt(*this)*=a;}};
// double pnt::eps = 1e-10;
// 
// ull pw(ull a, ull b, ull m){ull r=1;while(b){if(b&1)r=r*a%m;b>>=1;a=a*a%m;}return r;}
// int get_inv(ll a, int md){ll t=a,s=md,u=1,v=0,e;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 fft(int n, pnt x[], void *mem){int i,j,I,J,K,s=1;double t=2*PI/n,p;pnt w,v,u,a,b,c,d,A,B,C,D,*y=(pnt*)mem;while(n>2){I=n/4;J=I+I;K=I+J;rep(i,I){w=pnt(cos(i*t),-sin(i*t));v=w*w;u=w*v;rep(j,s)a=x[j+s*i],b=x[j+s*(i+I)],c=x[j+s*(i+J)],d=x[j+s*(i+K)],A=a+c,B=a-c,C=b+d,D=b-d,p=D.y,D.y=D.x,D.x=-p,y[j+s*4*i]=A+C,y[j+s*(4*i+1)]=w*(B-D),y[j+s*(4*i+2)]=v*(A-C),y[j+s*(4*i+3)]=u*(B+D);}n/=4;s*=4;t*=4;swap(x,y);}if(n==2){rep(i,s)y[i]=x[i]+x[i+s],y[i+s]=x[i]-x[i+s];n/=2;s*=2;t*=2;swap(x,y);}rep(i,s)y[i]=x[i];}
// void fftinv(int n, pnt x[], void *mem){int i,j,I,J,K,s=1;double t=2*PI/n,p;pnt w,v,u,a,b,c,d,A,B,C,D,*y=(pnt*)mem;while(n>2){I=n/4;J=I+I;K=I+J;rep(i,I){w=pnt(cos(i*t),sin(i*t));v=w*w;u=w*v;rep(j,s)a=x[j+s*i],b=x[j+s*(i+I)],c=x[j+s*(i+J)],d=x[j+s*(i+K)],A=a+c,B=a-c,C=b+d,D=b-d,p=D.y,D.y=D.x,D.x=-p,y[j+s*4*i]=A+C,y[j+s*(4*i+1)]=w*(B+D),y[j+s*(4*i+2)]=v*(A-C),y[j+s*(4*i+3)]=u*(B-D);}n/=4;s*=4;t*=4;swap(x,y);}if(n==2){rep(i,s)y[i]=x[i]+x[i+s],y[i+s]=x[i]-x[i+s];n/=2;s*=2;t*=2;swap(x,y);}rep(i,s)y[i]=x[i];}
// void convolution(double A[], int As, double B[], int Bs, double res[], int Rs, void *mem){int i,n,k;double m;pnt*a,*b;n=max(As+Bs,Rs);for(k=1;k<n;k*=2);a=(pnt*)mem;b=a+k;mem=b+k;rep(i,As)a[i].set(A[i],0);REP(i,As,k)a[i].set(0,0);rep(i,Bs)b[i].set(B[i],0);REP(i,Bs,k)b[i].set(0,0);fft(k,a,mem);fft(k,b,mem);rep(i,k)a[i]*=b[i];fftinv(k,a,mem);m=1.0/k;rep(i,Rs)res[i]=a[i].x*m;}
// void convolution(double A[], int As, double res[], int Rs, void *mem){int i,n,k;double m;pnt*a;n=max(As+As,Rs);for(k=1;k<n;k*=2);a=(pnt*)mem;mem=a+k;rep(i,As)a[i].set(A[i],0);REP(i,As,k)a[i].set(0,0);fft(k,a,mem);rep(i,k)a[i]*=a[i];fftinv(k,a,mem);m=1.0/k;rep(i,Rs)res[i]=a[i].x*m;}
// 
// 
// int N, A[1d5];
// 
// double c[100001], cnv[200001];
// ll s[100001];
// int mn[100001];
// {
//   int i, j, k;
//   ll tk;
//   mint res, tmp;
//   double dmin, dtmp;
//   int *ddd;
// 
//   walloc1d(&ddd,1);
// 
//   rd(N,A(N));
// 
//   res = 1;
//   
//   rep(i,N) c[A[i]]++;
//   convolution(c, 100001, cnv, 200001, wmem);
//   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];
//       tmp *= mint(A[i]) ** mn[i+1];
//     }
//   }
// 
//   res /= tmp;
// 
//   wt(res);
// }
0