提交时间:2023-08-14 15:26:24
运行 ID: 98338
#include<bits/stdc++.h> using namespace std; #define ll long long const int N=2e5+5; ll n,a[N],b[N],ans,sum; namespace IO{ char buf[1<<21],*p1=buf,*p2=buf; inline int getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;} template<typename T>inline void read(T &ret){ ret=0;char ch=getc(); while(!isdigit(ch))ch=getc(); while(isdigit(ch))ret=(ret<<1)+(ret<<3)+(ch^48),ch=getc(); } } using namespace IO; int main(){ read(n); for(int i=1;i<=n;++i){ read(a[i]); for(ll j=a[i];j;j/=10) ans+=j%10; } ans*=n<<1; for(ll i=10;i<=1e15;i*=10){ sort(a+1,a+n+1,[&](ll X,ll Y){return X%i<Y%i;}); for(int j=1;j<=n;++j)b[j]=a[j]%i; for(int j=1;j<=n;++j) sum+=n+1-(lower_bound(b+1,b+n+1,i-b[j])-b); } printf("%lld\n",ans-sum*9); return 0; }