/* #include void self::main(){ LL(N); VL(N,a); sort(a); use_ml1000000007 pp(sum_pair_project_first(a)-sum_pair_mod(a)); } */ #include #include using namespace std; namespace self{void main();void sub();templatevoid pp(auto&&...a);void epp(auto&&...a);} int main(){cin.tie(nullptr)->sync_with_stdio(0);cout<__VA_ARGS__;fe(refs(__VA_ARGS__),e)e.get().resizes(n);lin(__VA_ARGS__) #define VL(n,...) RDVL(ll,n,__VA_ARGS__) #define FO(n) for(ll IJK=n;IJK-->0;) #define fo(i,...) for(auto[i,i##stop,i##step]=for_range(0,__VA_ARGS__);i(1,__VA_ARGS__);i>=i##stop;i+=i##step) #define fe(a,e,...) for(auto&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):a) #define use_ml1000000007 using ml=atcoder::modint1000000007; namespace self{ auto&operator<<(ostream&o,const atcoder::modint1000000007&x){return o<<(int)x.val();} using ll=long long; using ui32=uint32_t; using ui64=uint64_t; constexpr auto refs(auto&...a){return array{ref(a)...};} templateconstexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};} templateconstexpr auto for_range(T s,T a,T b,T c=1){return array{a-s,b,(1-s*2)*c};} void lin(auto&...a){(cin>>...>>a);} constexpr ui64 kth_root_floor(ui64 a,ll k){ if (k==1)return a; auto within=[&](ui32 x){ui64 t=1;FO(k)if(__builtin_mul_overflow(t,x,&t))return false;return t<=a;}; ui64 r=0; of(i,sizeof(ui32)*CHAR_BIT)if(within(r|(1u<>decltype(auto)sort(auto&&a,F f={}){ranges::sort(a,f);return a;} decltype(auto)unique(auto&&a){sort(a).erase(ranges::unique(a).begin(),a.end());return a;} templateusing pack_back_t=tuple_element_t>; templateclass Iterator{ private: I it_,begin_,end_; public: Iterator(I it,I begin,I end):it_(it),begin_(begin),end_(end){} ll dist()const{return it_-begin_;} }; } namespace self{ templateclass FenwickTree{ public: ll n_; vectordata_; FenwickTree(ll n):n_(n),data_(n){} void add(ll i,T x){ assert(0<=i&&i0)res+=data_[r-1],r-=r&-r; while(l>0)res-=data_[l-1],l-=l&-l; return res; } }; } namespace self{ templateistream&operator>>(istream&i,vector&v){fe(v,e)i>>e;return i;} templateconstexpr int depth=0; templatestruct core_t_helper{using type=T;}; templateusing core_t=core_t_helper::type; templatestruct vec; templatestruct hvec_helper{using type=vec::type>;}; templatestruct hvec_helper<0,T>{using type=T;}; templateusing hvec=hvec_helper::type; templatestruct vec:vector{ static constexpr int D=depth+1; using C=core_t; using vector::vector; void resizes(const auto&...a){if constexpr(sizeof...(a)==D)*this=make(a...,C{});else{ }} static auto make(ll n,const auto&...a){ if constexpr(sizeof...(a)==1)return vec(n,array{a...}[0]); else { } } ll size()const{return vector::size();} auto first_true(const V&x,auto&&f)const{ auto b=this->begin(),e=this->end(); auto p=partition_point(b,e,[&x,&f](const V&v){return !f(x,v);}); return Iterator{p,b,e}; } auto first_ge(const V&x)const{return first_true(x,[](auto&x,auto&e){return x<=e;});} }; templaterequires(sizeof...(A)>=2)vec(const A&...a)->vec>>; auto zip(auto&...a){auto v=(a^...);unique(v);([&](auto&u){fe(u,e)e=v.first_ge(e).dist();}(a),...);return v;} } namespace self{ templateT sum_pair_project_first(const vec&a){ ll n=a.size(); T res=0; fo(i,n)res+=T(n-1-i)*a[i]; return res; } templateT sum_pair_project_second(const vec&a){ T res=0; fo(i,a.size())res+=T(i)*a[i]; return res; } templateT sum_pair_mod(veca){ T A=sum_pair_project_second(a); auto z=zip(a); ll N=a.size(),K=z.size(); auto V=z.back(); auto R=sqrt_floor(V); FenwickTreefw(K); T res=0; vecF(R+1); of(i,N){ auto x=z[a[i]]; if(x<=R){ res+=x*F[x]; } else{ fo(q,1,V/x+1){ ll l=z.first_ge(x*q).dist(); res+=x*fw.sum(l,K); } } fo(d,1,R+1)F[d]+=x/d; fw.add(a[i],1); } return A-res; } } templatevoid self::pp(auto&&...a){const char*c="";((o<(a)-sum_pair_mod(a)); }