QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#140273#4554. 联通子树myee100 ✓2009ms34740kbC++1112.7kb2023-08-15 16:47:272023-08-15 16:47:30

Judging History

你现在查看的是最新测评结果

  • [2023-08-15 16:47:30]
  • 评测
  • 测评结果:100
  • 用时:2009ms
  • 内存:34740kb
  • [2023-08-15 16:47:27]
  • 提交

answer

// 那就是希望。
// 即便需要取模,也是光明。

#include <algorithm>
#include <stdio.h>
#include <vector>
typedef long long llt;
typedef unsigned uint;typedef unsigned long long ullt;
typedef bool bol;typedef char chr;typedef void voi;
typedef double dbl;
template<typename T>bol _max(T&a,T b){return(a<b)?a=b,true:false;}
template<typename T>bol _min(T&a,T b){return(b<a)?a=b,true:false;}
template<typename T>T lowbit(T n){return n&-n;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T lcm(T a,T b){return(a!=0||b!=0)?a/gcd(a,b)*b:(T)0;}
template<typename T>T exgcd(T a,T b,T&x,T&y){if(b!=0){T ans=exgcd(b,a%b,y,x);y-=a/b*x;return ans;}else return y=0,x=1,a;}
template<typename T>T power(T base,T index,T mod)
{
    T ans=1%mod;
    while(index)
    {
        if(index&1)ans=ans*base%mod;
        base=base*base%mod,index>>=1;
    }
    return ans;
}
namespace ConstMod
{
    template<const ullt p>
    class mod_ullt
    {
        private:
            ullt v;
            inline ullt chg(ullt w){return(w<p)?w:w-p;}
            inline mod_ullt _chg(ullt w){mod_ullt ans;ans.v=(w<p)?w:w-p;return ans;}
        public:
            mod_ullt():v(0){}
            mod_ullt(ullt v):v(v%p){}
            bol empty(){return!v;}
            inline ullt val(){return v;}
            friend bol operator<(mod_ullt a,mod_ullt b){return a.v<b.v;}
            friend bol operator>(mod_ullt a,mod_ullt b){return a.v>b.v;}
            friend bol operator<=(mod_ullt a,mod_ullt b){return a.v<=b.v;}
            friend bol operator>=(mod_ullt a,mod_ullt b){return a.v>=b.v;}
            friend bol operator==(mod_ullt a,mod_ullt b){return a.v==b.v;}
            friend bol operator!=(mod_ullt a,mod_ullt b){return a.v!=b.v;}
            inline friend mod_ullt operator+(mod_ullt a,mod_ullt b){return a._chg(a.v+b.v);}
            inline friend mod_ullt operator-(mod_ullt a,mod_ullt b){return a._chg(a.v+a.chg(p-b.v));}
            inline friend mod_ullt operator*(mod_ullt a,mod_ullt b){return a.v*b.v;}
            friend mod_ullt operator/(mod_ullt a,mod_ullt b){return b._power(p-2)*a.v;}
            friend mod_ullt operator^(mod_ullt a,ullt b){return a._power(b);}
            inline mod_ullt operator-(){return _chg(p-v);}
            mod_ullt sqrt()
            {
                if(power(v,(p-1)>>1,p)!=1)return 0;
                mod_ullt b=1;do b++;while(b._power((p-1)>>1)==1);
                ullt t=p-1,s=0,k=1;while(!(t&1))s++,t>>=1;
                mod_ullt x=_power((t+1)>>1),e=_power(t);
                while(k<s)
                {
                    if(e._power(1llu<<(s-k-1))!=1)x*=b._power((1llu<<(k-1))*t);
                    e=_power(p-2)*x*x,k++;
                }
                return _min(x,-x),x;
            }
            mod_ullt inv(){return _power(p-2);}
            mod_ullt _power(ullt index){mod_ullt ans(1),w(v);while(index){if(index&1)ans*=w;w*=w,index>>=1;}return ans;}
            voi read(){v=0;chr c;do c=getchar();while(c>'9'||c<'0');do v=(c-'0'+v*10)%p,c=getchar();while(c>='0'&&c<='9');v%=p;}
            voi print()
            {
                static chr C[20];uint tp=0;
                ullt w=v;do C[tp++]=w%10+'0',w/=10;while(w);
                while(tp--)putchar(C[tp]);
            }
            voi println(){print(),putchar('\n');}
            mod_ullt operator++(int){mod_ullt ans=*this;return v=chg(v+1),ans;}
        public:
            inline ullt&operator()(){return v;}
            inline mod_ullt&operator+=(mod_ullt b){return*this=_chg(v+b.v);}
            inline mod_ullt&operator-=(mod_ullt b){return*this=_chg(v+chg(p-b.v));}
            inline mod_ullt&operator*=(mod_ullt b){return*this=v*b.v;}
            mod_ullt&operator^=(ullt b){return*this=_power(b);}
            mod_ullt&operator/=(mod_ullt b){return*this=b._power(p-2)*v;}
            mod_ullt&operator++(){return v=chg(v+1),*this;}
    };
}
// Heaven and Earth... My guiding star...
const ullt Mod=1e9+7;
typedef ConstMod::mod_ullt<Mod>modint;
typedef std::vector<modint>modvec;
std::vector<uint>Way[100005],P[100005];
uint Siz[100005],Dep[100005],Heavy[100005],Fath[100005],Rot[100005];
uint Dfn[100005],End[100005],Back[100005];
modint Dp[100005],DpF[100005],W[100005],Mul[100005],S[100005],SLeft[100005];uint Cnt[100005];
voi dfs1(uint p,uint f)
{
    Fath[p]=f,Siz[p]=1,Heavy[p]=-1,Dp[p]=1;
    for(auto s:Way[p])if(s!=f)
    {
        Dep[s]=Dep[p]+1,dfs1(s,p),Siz[p]+=Siz[s],Dp[p]*=Dp[s]+1,SLeft[p]+=S[s];
        if(!~Heavy[p]||Siz[Heavy[p]]<Siz[s])Heavy[p]=s;
    }
    S[p]=SLeft[p]+Dp[p];if(~Heavy[p])SLeft[p]-=S[Heavy[p]];
}
voi dfs2(uint p,uint r)
{
    static uint cnt=0;
    Rot[p]=r,Back[Dfn[p]=cnt++]=p,W[p]=Mul[p]=1;
    for(auto s:Way[p]){modint w=((s==Fath[p])?DpF[p]:Dp[s])+1;if(w())Mul[p]*=w;else Cnt[p]++;}
    if(~Heavy[p])
    {
        for(auto s:Way[p])if(s!=Fath[p])DpF[s]=Cnt[p]?(Cnt[p]>1?0:((Dp[s]+1)()?0:Mul[p])):Mul[p]/(Dp[s]+1);
        dfs2(Heavy[p],r);for(auto s:Way[p])if(s!=Fath[p]&&s!=Heavy[p])dfs2(s,s),W[p]*=Dp[s]+1;
    }
    End[p]=cnt;
}
uint lca(uint u,uint v)
{
    while(Rot[u]!=Rot[v])
    {
        if(Dep[Rot[u]]<Dep[Rot[v]])std::swap(u,v);
        u=Fath[Rot[u]];
    }
    return Dep[u]<Dep[v]?u:v;
}
std::pair<modint,uint>PreSum[100005];
modint PreAll[100005],SufAll[100005],SumSLeft[100005];
uint Op[55],n0,n1,n2;bol G[55];
uint U[55],V[55];modint Wg[2][55],Wc[55],Wp[55];
std::vector<uint>E[55],Q;
modint We[55],Wne[55],ans;
uint F[55],R[55],c0,c1,c2;
uint getsiz(uint p,uint f)
{
    uint ans=1,s;
    for(auto e:E[p])if(!G[s=U[e]^V[e]^p]&&s!=f)ans+=getsiz(s,p);
    return ans;
}
uint getwp(uint p,uint f,uint siz,uint&w,uint&wp)
{
    uint ans=1,t=0,user,s;
    for(auto e:E[p])if(!G[s=U[e]^V[e]^p]&&s!=f)ans+=user=getwp(s,p,siz,w,wp),_max(t,user);
    _max(t,siz-ans);if(_min(w,t))wp=p;
    return ans;
}
voi dfs(uint p,uint f)
{
    if(~Op[p]){if(!Op[p])c0++;else if(Op[p]==1)c1++;else if(Op[p]==2)c2++;}
    uint s;R[p]=Q.size(),Q.push_back(p),F[p]=f,We[p]=Wp[p];
    for(auto e:E[p])if((s=U[e]^V[e]^p)==f)We[p]*=Wc[e],Wne[p]=Wg[f==V[e]][e];
        else if(!G[s])dfs(s,p);else We[p]*=Wg[p==V[e]][e];
}
voi solve(uint p)
{
    {uint n=getsiz(p,-1);getwp(p,-1,n,n,p);}
    c0=c1=c2=0,Q.clear(),dfs(p,-1);if(c0<n0||c1<n1||c2<n2)return;
    static modint Dp[55][6][6][6];
    for(uint i=0;i<=n0;i++)for(uint j=0;j<=n1;j++)for(uint k=0;k<=n2;k++)Dp[0][i][j][k]=0;
    Dp[0][!Op[p]][Op[p]==1][Op[p]==2]=We[p];
    for(uint c=1;c<Q.size();c++)
    {
        if(!~Op[Q[c]])
        {
            for(uint i=0;i<=n0;i++)for(uint j=0;j<=n1;j++)for(uint k=0;k<=n2;k++)
                Dp[c][i][j][k]=Dp[R[F[Q[c]]]][i][j][k];
        }
        else if(!Op[Q[c]])
        {
            for(uint j=0;j<=n1;j++)for(uint k=0;k<=n2;k++)Dp[c][0][j][k]=0;
            for(uint i=1;i<=n0;i++)for(uint j=0;j<=n1;j++)for(uint k=0;k<=n2;k++)
                Dp[c][i][j][k]=Dp[R[F[Q[c]]]][i-1][j][k];
        }
        else if(Op[Q[c]]==1)
        {
            for(uint i=0;i<=n0;i++)for(uint k=0;k<=n2;k++)Dp[c][i][0][k]=0;
            for(uint i=0;i<=n0;i++)for(uint j=1;j<=n1;j++)for(uint k=0;k<=n2;k++)
                Dp[c][i][j][k]=Dp[R[F[Q[c]]]][i][j-1][k];
        }
        else
        {
            for(uint i=0;i<=n0;i++)for(uint j=0;j<=n1;j++)Dp[c][i][j][0]=0;
            for(uint i=0;i<=n0;i++)for(uint j=0;j<=n1;j++)for(uint k=1;k<=n2;k++)
                Dp[c][i][j][k]=Dp[R[F[Q[c]]]][i][j][k-1];
        }
        for(uint t=Q[c];t!=(c==Q.size()-1?p:F[Q[c+1]]);t=F[t])
            for(uint i=0;i<=n0;i++)for(uint j=0;j<=n1;j++)for(uint k=0;k<=n2;k++)
                Dp[R[F[t]]][i][j][k]=Dp[R[F[t]]][i][j][k]*Wne[t]+Dp[R[t]][i][j][k]*We[t];
    }
    ans+=Dp[0][n0][n1][n2],G[p]=1;for(auto e:E[p])if(!G[U[e]^V[e]^p])solve(U[e]^V[e]^p);
}
namespace Seg
{
    const uint Lim=131072;
    struct Info
    {
        modint mul,pre,suf,sum;
        friend Info operator+(Info a,Info b)
        {
            return{a.mul*b.mul,a.pre+a.mul*b.pre,a.suf*b.mul+b.suf,a.sum+b.sum+a.suf*b.pre};
        }
    };
    Info Val[Lim<<1|1];
    voi build()
    {
        for(uint i=0;i<100000;i++)Val[i|Lim]={W[Back[i]],W[Back[i]],W[Back[i]],W[Back[i]]};
        for(uint i=Lim-1;i;i--)Val[i]=Val[i<<1]+Val[i<<1|1];
    }
    Info find(uint u,uint l,uint r,uint n)
    {
        if(l>=r)return{1,0,0,0};
        if(!l&&r==n)return Val[u];
        if(l<(n>>1))
            if(r<=(n>>1))return find(u<<1,l,r,n>>1);
            else return find(u<<1,l,n>>1,n>>1)+find(u<<1|1,0,r-(n>>1),n>>1);
        else return find(u<<1|1,l-(n>>1),r-(n>>1),n>>1);
    }
    modint query(uint l,uint r){return find(1,l,r,Lim).sum;}
}
int main()
{
#ifdef MYEE
    freopen("QAQ.in","r",stdin);
    freopen("QAQ.out","w",stdout);
#endif
    uint n,q;scanf("%u%u",&n,&q);
    for(uint i=0,c;i<n;i++)scanf("%u",&c),P[c-1].push_back(i);
    for(uint i=1,u,v;i<n;i++)scanf("%u%u",&u,&v),Way[--u].push_back(--v),Way[v].push_back(u);
    dfs1(0,-1),dfs2(0,0),PreSum[0]={1,0};
    for(uint i=0;i<n;i++)
        PreSum[i+1]=W[Back[i]]()?std::pair<modint,uint>{PreSum[i].first*W[Back[i]],PreSum[i].second}
                                :std::pair<modint,uint>{PreSum[i].first,PreSum[i].second+1},
        SumSLeft[i+1]=SumSLeft[i]+SLeft[Back[i]],PreAll[i+1]=(PreAll[i]+1)*W[Back[i]];
    SufAll[n]=1;for(uint i=n-1;~i;i--)SufAll[i]=SufAll[i+1]*W[Back[i]]+1;
    Seg::build();
    while(q--)
    {
        static uint Id[100005],C[55],a,b,c;scanf("%u%u%u%u%u%u",&a,&n0,&b,&n1,&c,&n2);
        if(P[--a].size()<n0||P[--b].size()<n1||P[--c].size()<n2){puts("0");continue;}
        Q={0};
        for(auto s:P[a])Q.push_back(s);
        for(auto s:P[b])Q.push_back(s);
        for(auto s:P[c])Q.push_back(s);
        std::sort(Q.begin(),Q.end(),[&](uint a,uint b){return Dfn[a]<Dfn[b];});
        for(uint i=Q.size()-1;i;i--)Q.push_back(lca(Q[i],Q[i-1]));
        std::sort(Q.begin(),Q.end(),[&](uint a,uint b){return Dfn[a]<Dfn[b];});
        Q.erase(std::unique(Q.begin(),Q.end()),Q.end());
        F[0]=-1;for(uint i=0;i<Q.size();i++)Id[Q[i]]=i,Op[i]=-1,G[i]=false;
        for(auto s:P[a])Op[Id[s]]=0;
        for(auto s:P[b])Op[Id[s]]=1;
        for(auto s:P[c])Op[Id[s]]=2;
        for(uint i=0;i<Q.size();i++)E[i].clear(),Wp[i]=Mul[Q[i]],C[i]=Cnt[Q[i]];
        for(uint i=1;i<Q.size();i++)
        {
            uint f=lca(Q[i],Q[i-1]);uint t=Heavy[f];modint mul=1,pre=1,suf=1,w;
            for(uint j=Q[i],l,r;;)
            {
                l=Rot[j]==Rot[f]?Dfn[f]+1:Dfn[Rot[j]],r=Dfn[j];
                w=PreSum[l].second==PreSum[r].second?PreSum[r].first/PreSum[l].first:0,
                pre=pre+mul*(PreAll[r]-PreAll[l]*w),suf=suf*w+(SufAll[l]-SufAll[r]*w),mul*=w;
                if(Rot[j]==Rot[f])break;
                else if(Fath[Rot[j]]==f){t=Rot[j];break;}
                else
                {
                    j=Rot[j];
                    w=Cnt[Fath[j]]?(Cnt[Fath[j]]>1||(Dp[j]+1)())?0:Dp[Fath[j]]:Dp[Fath[j]]/(Dp[j]+1);
                    suf=suf*w+1,pre+=mul*=w;
                    j=Fath[j];
                }
            }
            U[i-1]=i,V[i-1]=Id[f],Wg[0][i-1]=pre,Wg[1][i-1]=suf,Wc[i-1]=mul;
            if((DpF[Q[i]]+1)())Wp[i]/=DpF[Q[i]]+1;else C[i]--;
            if((Dp[t]+1)())Wp[Id[f]]/=Dp[t]+1;else C[Id[f]]--;
            E[i].push_back(i-1),E[Id[f]].push_back(i-1);
        }
        for(uint i=0;i<Q.size();i++)if(C[i])Wp[i]=0;
        ans=0;
        if(!n0&&!n1&&!n2)
        {
            ans+=S[0]-Dp[0];
            for(uint i=1;i<Q.size();i++)
            {
                uint f=lca(Q[i],Q[i-1]);uint t=Heavy[f];modint suf=1,w;
                for(uint j=Q[i],l,r;;)
                {
                    l=Rot[j]==Rot[f]?Dfn[f]+1:Dfn[Rot[j]],r=Dfn[j];
                    w=PreSum[l].second==PreSum[r].second?PreSum[r].first/PreSum[l].first:0,
                    ans+=SumSLeft[r]-SumSLeft[l]+(suf-1)*(PreAll[r]-PreAll[l]*w)+Seg::query(l,r);
                    suf=suf*w+(SufAll[l]-SufAll[r]*w);
                    if(Rot[j]==Rot[f])break;
                    else if(Fath[Rot[j]]==f){t=Rot[j];break;}
                    else
                    {
                        j=Rot[j];
                        w=Mul[Fath[j]];uint c=Cnt[Fath[j]];
                        if((Dp[j]+1)())w/=Dp[j]+1;else c--;
                        if((DpF[Fath[j]]+1)())w/=DpF[Fath[j]]+1;else c--;
                        if(c)w=0;
                        ans+=S[Fath[j]]-Dp[Fath[j]]-S[j]+suf*w,suf=suf*w+1;
                        j=Fath[j];
                    }
                }
                ans+=S[Q[i]]-Dp[Q[i]]-S[t];
            }
        }
        solve(0),ans.println();
    }
    return 0;
}

// 那就是希望。
// 即便需要取模,也是光明。

詳細信息

Test #1:

score: 5
Accepted
time: 0ms
memory: 28100kb

input:

5 10
1 1 3 1 2
1 2
2 3
2 4
3 5
1 0 2 0 3 1
2 0 3 0 1 1
2 1 1 3 3 1
2 0 3 1 1 2
2 1 3 1 1 2
2 1 3 0 1 3
3 1 1 1 2 0
3 0 2 1 1 0
3 1 1 0 2 1
2 1 3 0 1 3

output:

1
3
1
2
2
0
1
1
1
0

result:

ok 10 numbers

Test #2:

score: 5
Accepted
time: 0ms
memory: 27980kb

input:

10 10
1 4 3 4 1 2 3 2 4 2
1 2
2 3
2 4
1 5
1 6
4 7
5 8
5 9
1 10
2 0 1 0 4 2
1 1 2 3 4 2
2 0 1 0 4 2
3 0 4 0 1 2
2 3 4 0 1 0
2 1 4 0 1 0
1 0 4 1 3 0
4 2 2 2 3 2
1 0 2 0 3 0
1 1 2 0 4 3

output:

4
0
4
8
0
3
3
4
4
0

result:

ok 10 numbers

Test #3:

score: 5
Accepted
time: 3ms
memory: 28188kb

input:

15 50
1 4 1 5 5 1 2 4 5 1 1 5 3 5 4
1 2
2 3
1 4
1 5
2 6
3 7
2 8
1 9
1 10
1 11
7 12
2 13
1 14
13 15
4 2 3 0 1 0
5 3 1 2 4 0
3 1 1 0 2 1
1 5 2 0 3 0
1 4 5 2 4 0
1 2 2 1 5 5
4 2 5 2 1 3
2 0 4 3 5 2
1 1 2 0 4 3
5 0 2 1 1 4
1 5 4 3 3 0
2 0 4 0 5 5
3 0 5 4 2 0
4 1 2 1 5 4
1 3 3 1 5 4
4 0 2 0 3 1
1 0 4 1 3...

output:

1
8
0
32
0
6
198
96
18
18
0
0
36
80
84
1
2
60
128
162
262
192
36
2
0
0
84
176
102
68
56
64
260
0
192
112
0
30
0
36
260
60
32
126
31
8
6
0
9
262

result:

ok 50 numbers

Test #4:

score: 5
Accepted
time: 1ms
memory: 28200kb

input:

15 50
4 4 5 2 1 1 2 4 2 2 1 5 5 1 2
1 2
2 3
3 4
3 5
4 6
4 7
4 8
1 9
7 10
3 11
9 12
12 13
4 14
3 15
3 0 5 0 1 3
4 2 2 1 5 3
4 2 1 3 2 2
4 0 3 0 2 1
4 1 5 2 1 0
4 3 2 2 5 1
2 2 3 0 1 0
5 0 2 3 1 1
5 2 3 0 1 0
4 3 5 3 3 0
5 0 3 0 4 1
1 3 5 0 4 2
1 1 2 1 4 0
5 2 1 2 2 2
3 0 2 3 5 1
1 1 2 3 5 0
2 1 1 4 4...

output:

0
4
28
30
1
48
24
4
18
96
16
0
8
13
256
4
1
36
16
12
16
60
20
4
228
61
6
6
32
80
104
38
38
16
2
2
80
52
1
48
5
28
2
0
10
20
48
20
52
0

result:

ok 50 numbers

Test #5:

score: 5
Accepted
time: 14ms
memory: 28556kb

input:

1000 1000
266 90 111 86 237 174 221 276 192 32 249 136 98 20 228 38 223 220 284 179 255 158 140 196 241 118 48 244 165 193 51 286 159 43 176 144 69 111 36 237 145 266 271 28 288 267 30 123 200 142 227 209 11 224 298 112 170 293 100 168 259 270 47 117 188 79 206 5 166 110 100 212 14 202 1 38 279 269 ...

output:

65098538
132554937
926339017
529588494
921231528
290125346
890345448
210073194
170174844
622914632
254885454
409741392
0
122788237
593872032
645315657
490355203
526433224
564754684
56468793
818713750
175649474
510178333
658026468
922618319
316915657
4608891
695488288
505012318
747857608
400173957
23...

result:

ok 1000 numbers

Test #6:

score: 5
Accepted
time: 16ms
memory: 28024kb

input:

1000 1000
118 138 198 43 181 54 128 270 49 165 18 179 169 171 113 243 51 35 174 178 48 137 156 236 219 226 20 10 291 47 142 265 165 126 40 100 247 275 250 245 200 36 289 220 13 185 231 72 10 89 94 51 162 11 177 6 139 218 190 127 220 226 38 294 61 157 256 197 250 163 142 195 76 290 150 188 127 230 13...

output:

12278776
435337143
455701828
803175028
281326340
48474006
181348519
765747523
847600604
729505045
666847208
348158854
136634495
610224728
874074496
151029946
46802492
137918701
458386922
430742942
391503445
262903567
37054476
323571221
8393618
315783539
227312205
724653843
279468524
394173221
512993...

result:

ok 1000 numbers

Test #7:

score: 5
Accepted
time: 939ms
memory: 30396kb

input:

50000 50000
6271 2161 8645 12531 13681 14634 4058 8472 3574 13129 10626 7913 9431 12635 654 380 1486 14727 7795 10377 3440 11216 12528 12344 12554 6566 9715 2952 4848 7701 14508 1321 415 12684 4880 9300 13148 12031 3888 3909 8411 12173 10399 4776 7962 1043 7688 5777 8995 8680 1517 6250 10677 3031 92...

output:

513219003
441903217
246477800
560413569
116007885
74532801
803196464
860260209
87163373
582095914
607999262
961091320
24862839
702318123
365789611
134753446
45512458
624524541
39313765
757409452
252943803
226630136
742936867
895099306
587261929
765097473
867007272
935644029
217401846
464044579
13927...

result:

ok 50000 numbers

Test #8:

score: 5
Accepted
time: 2009ms
memory: 32792kb

input:

100000 100000
25323 21952 1724 4564 25924 25014 26764 1442 16456 29326 5595 29624 4770 63 21664 27749 8213 25042 9716 1308 2933 9463 25512 29592 21164 26830 19519 20594 18774 5454 2543 27277 25621 26674 3012 24923 19150 15687 28701 2117 10090 16319 3518 18167 19511 22737 8844 25650 9172 6103 8884 26...

output:

769702737
388620691
285063753
734511865
341725169
610580800
200180141
1091462
38514026
903408885
123042391
48536729
782772109
80525572
208386643
202805887
888883970
828663666
28806854
343935366
177242557
890733120
629717585
403401926
119871363
484861095
207257939
42884850
150052604
816149736
7929225...

result:

ok 100000 numbers

Test #9:

score: 5
Accepted
time: 1307ms
memory: 34624kb

input:

100000 100000
14376 20799 15746 5653 2224 5394 22239 6237 5281 21059 25028 18159 24165 19851 28081 15653 12172 8534 11637 25007 5194 22709 17960 19200 2134 20270 28914 8237 2700 17800 29634 20465 20827 10256 28376 10955 1096 4343 5339 15325 11769 2289 8868 13791 7003 26663 12769 18699 12525 6293 103...

output:

773309997
995297164
127576428
995593440
94700436
0
556567157
638642504
547636039
664950514
855289131
158609441
423427850
818435126
251184943
387441578
0
602830145
645789138
917168611
336960163
77165127
157201340
915513554
608003820
844750519
363985859
624015790
516223400
357340447
32868660
559922419...

result:

ok 100000 numbers

Test #10:

score: 5
Accepted
time: 1310ms
memory: 34632kb

input:

100000 100000
3428 10591 11593 9509 29468 15774 26769 29207 21338 10023 8173 22101 4504 22278 16322 790 4307 6617 16326 18706 1918 3188 25000 6040 25744 28302 26486 28647 13857 18321 14900 16420 6977 9246 11916 11578 22098 11175 11977 25765 13448 6434 1579 9415 784 589 2102 26340 24935 6484 8962 225...

output:

496153554
531788782
227809595
617686504
466875459
0
0
3627468
412916553
271666759
175894086
0
570382948
436465014
0
22210546
24659602
373972239
485077673
0
375232912
0
635384988
104825976
834494878
480396821
249257190
8360058
505336397
62923308
481909214
690117604
404074764
211851019
73635560
170525...

result:

ok 100000 numbers

Test #11:

score: 5
Accepted
time: 1284ms
memory: 34672kb

input:

100000 100000
22481 9438 4672 10598 11304 26154 22243 19409 10163 26220 27606 7868 26666 242 7331 4103 8266 20109 21016 9638 4179 16435 20216 22880 22122 21742 24057 16289 25015 16075 2935 12376 2183 25596 7280 9434 13099 27063 4022 8973 12360 22404 9697 5038 101 4514 6026 1213 25520 3907 1329 22123...

output:

0
656312037
0
884048204
612346432
563887270
264236948
308240686
754725067
0
838862159
971488529
716447442
237773761
317440137
744641095
380352477
894298644
0
708859569
339570304
993831640
427727854
895362047
323343944
624089763
240438950
853690129
767373053
585493239
559167033
441736748
567237103
27...

result:

ok 100000 numbers

Test #12:

score: 5
Accepted
time: 1285ms
memory: 34740kb

input:

100000 100000
8765 29229 18695 17223 5780 6534 14950 24203 26221 15185 22575 14578 16061 14494 25572 22008 3169 3601 20169 21513 3672 24146 27256 9720 324 27006 685 3931 8941 16597 18202 8332 27389 27354 23588 25465 25045 15719 10660 19414 14039 8374 2407 3430 14826 11208 7183 21494 10697 4098 2752 ...

output:

161016891
870901994
703189866
179837696
181038857
667473649
684109091
91559324
781775533
205524460
255232644
168939886
110917953
0
0
223254029
257971320
911769829
360949679
27040088
0
536558006
71314488
474969780
457171270
874885635
139217295
713777
689051240
511178134
0
714044951
307904806
41691905...

result:

ok 100000 numbers

Test #13:

score: 5
Accepted
time: 1540ms
memory: 34556kb

input:

100000 100000
585 28077 11773 18312 14848 16914 22248 14405 24102 6917 184 3113 26400 22457 1989 7144 7128 28916 24858 15212 3164 25569 19703 29327 23934 23214 25488 21573 4690 14350 15293 16112 13539 8168 18952 26089 16047 22551 20066 2622 15718 12520 7758 26286 11375 12366 11108 26367 11282 1521 2...

output:

130957747
945276817
248000673
81650483
51785039
189312154
777400186
259369326
500927061
124287690
474543490
800026787
648699760
646996514
415037053
466739804
507140599
959357887
747854096
545035991
125316687
879742660
552002641
731678167
175039864
636922621
818018091
551788288
887480279
857096506
93...

result:

ok 100000 numbers

Test #14:

score: 5
Accepted
time: 1573ms
memory: 34676kb

input:

100000 100000
19638 15100 4852 19400 9324 27294 14954 7375 10159 25882 25153 9824 18563 9477 22998 22281 11087 12408 26779 8911 2657 8816 17687 16167 20312 28478 25828 21039 15848 26696 6095 12067 8745 9926 5260 14889 7048 11206 14879 27654 17397 28489 27700 10086 7923 19060 440 19415 23692 13536 26...

output:

683365283
234481142
46966292
236060941
138749903
374441378
751215006
916016087
820015000
748444710
227993231
918242672
297017638
364758359
283808414
763743190
588050445
479570416
880658668
196218300
873055696
605012529
115478291
849829638
449753837
865875512
880816953
788140426
910100364
308109293
9...

result:

ok 100000 numbers

Test #15:

score: 5
Accepted
time: 1630ms
memory: 34700kb

input:

100000 100000
5922 13947 27931 23257 18392 10442 7661 12169 26216 12079 14586 25590 26134 14673 8471 10186 3222 7723 1469 29842 4918 19295 21959 3007 28514 21918 2455 8681 29774 24450 21362 8023 3951 23509 624 12744 18994 27094 21517 10862 19076 14459 8587 5709 25416 4810 4365 27056 29813 10959 2796...

output:

891039068
399554914
320296851
8708670
291393015
445692559
125221353
29750412
873878918
128285821
0
575638131
86711913
554690578
616921459
423522536
337676233
169082503
326085879
97477182
159221399
372760245
765068122
220291385
817126518
82492050
884412851
745106123
536548425
206276505
463390564
7059...

result:

ok 100000 numbers

Test #16:

score: 5
Accepted
time: 1578ms
memory: 34704kb

input:

100000 100000
24975 6507 11954 24346 15636 20822 12191 5139 15041 3811 27731 11357 18296 19868 17656 25323 7182 21215 622 23541 1642 2542 19943 22615 22124 27182 27 26323 13699 22203 18453 3979 20101 25267 25988 13368 9996 15750 16331 21302 20755 21373 16705 1333 19197 8736 5521 29161 12222 8382 175...

output:

91903992
598961929
905442940
890192113
119728808
92469066
519564589
694635511
957041786
870820696
564364230
373700408
218460329
291250761
646847536
346216149
461481787
928478799
674103616
62741077
480278120
924589768
910527635
57397082
618958542
857206854
701816199
711710609
71271203
652358539
43198...

result:

ok 100000 numbers

Test #17:

score: 5
Accepted
time: 1610ms
memory: 34632kb

input:

100000 100000
16795 5354 7800 28203 24704 1202 7665 25341 1099 10952 17164 18067 28635 6888 5897 13227 2085 19299 5311 17240 3903 10253 24215 9455 326 26158 9423 13965 24857 22725 6488 29935 15308 6081 9528 29399 997 22582 22968 1742 7842 7342 3879 29725 18514 12662 6678 22210 12807 8573 18986 15730...

output:

605580638
755421467
490350999
211854246
253594174
548181425
447375325
221147746
742534237
941327593
598314931
850898938
529108335
320835328
84615865
808466530
502859202
463019015
72647313
40766459
146379470
542577821
205125671
842304425
625683478
166231578
978679312
62133984
837568481
466264690
7055...

result:

ok 100000 numbers

Test #18:

score: 5
Accepted
time: 1627ms
memory: 34556kb

input:

100000 100000
3079 22377 879 29291 21948 11582 372 27367 19924 29917 12133 6602 18030 12084 24138 28364 6044 2790 10000 10939 3396 23499 19431 26295 26704 19599 6994 28839 8783 2303 21754 25890 13282 7839 4892 27255 10175 11238 29606 14950 9521 11488 14766 22580 471 19356 28779 27083 27985 8763 1135...

output:

758706683
323909805
114156651
786368467
327160384
751002327
192591584
915321785
60639023
71669026
838696105
68173759
851747141
844891892
433528472
136639886
373668307
502475638
446900596
328356001
88756288
169670211
214501089
269578162
823522299
73438712
674664472
984882879
966855677
344414952
92316...

result:

ok 100000 numbers

Test #19:

score: 5
Accepted
time: 1562ms
memory: 34660kb

input:

100000 100000
22132 9401 14902 21324 28248 21962 7670 20337 17805 16113 22510 13313 28369 17279 3323 13501 28179 28106 11921 20046 120 6746 26471 1311 23082 24863 1798 16481 22708 2824 21613 21846 29432 24189 18432 16055 3945 29894 24420 25390 11201 27458 4708 20972 29787 20513 29935 1956 28570 6186...

output:

576116885
154225206
133748650
266496301
867124772
839785204
466845968
36993283
685862236
896397842
316435334
620725921
83109441
363776624
573813394
301987859
455616042
948824345
878032392
927184857
746124891
150306853
454151459
170888212
725391021
664333120
526150624
212843080
9984888
292591042
9059...

result:

ok 100000 numbers

Test #20:

score: 5
Accepted
time: 1626ms
memory: 34620kb

input:

100000 100000
11184 11016 7980 22413 25492 2342 376 10540 3862 7846 14711 29079 20531 4299 21564 1405 2138 11597 13843 13745 2381 17225 21686 20919 28516 18303 11193 4123 3866 578 6880 29626 24638 23179 16563 16678 24947 3958 28289 11366 12880 13428 12826 16596 26336 27207 3860 25005 10979 6377 1696...

output:

13770602
648010743
409202392
512274869
373051609
627121162
763450747
320150735
619798009
609095439
753349987
531627612
971553564
667878548
453113402
839691419
377524024
163681153
447199480
645672293
743074835
30618042
430423036
458780065
0
852766820
50254962
520355955
465387303
639628729
412571197
7...

result:

ok 100000 numbers

Extra Test:

score: 0
Extra Test Passed