ll@n,@a[n],@b[],r[];rep(i,n)r[i]=-1d12*~-b[i]/a[i];sortA(n,r,a,b);Mint s,x=1;rep(i,n)s+=a[i]*x,x*=b[i];wt(s);