1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<algorithm>
5 using namespace std;
6 typedef long long ll;
7 int Mod=19260817;
8 int n,sz;
9 ll ans,sum1[300001],sum2[300001],has[300001],a[300001],b[300001];
10 ll c[1200001][3];
11 void pushup(int rt,int p)
12 {
13 c[rt][p]=(c[rt*2][p]+c[rt*2+1][p])%Mod;
14 }
15 void update(int rt,int l,int r,int x,ll d,int p)
16 {
17 if (l==r)
18 {
19 c[rt][p]+=d;
20 c[rt][p]%=Mod;
21 return;
22 }
23 int mid=(l+r)/2;
24 if (x<=mid) update(rt*2,l,mid,x,d,p);
25 else update(rt*2+1,mid+1,r,x,d,p);
26 pushup(rt,p);
27 }
28 ll query(int rt,int l,int r,int L,int R,int p)
29 {
30 if (l>=L&&r<=R)
31 {
32 return c[rt][p];
33 }
34 int mid=(l+r)/2;
35 ll s=0;
36 if (L<=mid) s+=query(rt*2,l,mid,L,R,p);
37 s%=Mod;
38 if (R>mid) s+=query(rt*2+1,mid+1,r,L,R,p);
39 s%=Mod;
40 return s;
41 }
42 int main()
43 {
44 int i;
45 cin>>n;
46 for (i=1; i<=n; i++)
47 {
48 scanf("%lld",&a[i]);
49 b[i]=a[i];
50 }
51 sort(b+1,b+n+1);
52 sz=unique(b+1,b+n+1)-(b+1);
53 for (i=1; i<=n; i++)
54 {
55 ll x=a[i];
56 a[i]=lower_bound(b+1,b+sz+1,a[i])-b;
57 has[a[i]]=x%Mod;
58 }
59 for (i=1; i<=n; i++)
60 {
61 if (a[i]-1>=1)
62 sum1[i]=query(1,1,sz,1,a[i]-1,1)%Mod;
63 update(1,1,sz,a[i],has[a[i]],1);
64 }
65 for (i=n; i>=1; i--)
66 {
67 if (a[i]+1<=sz)
68 sum2[i]=query(1,1,sz,a[i]+1,sz,2)%Mod;
69 update(1,1,sz,a[i],has[a[i]],2);
70 }
71 for (i=2; i<n; i++)
72 {
73 ans+=(has[a[i]]*sum1[i]%Mod)*sum2[i]%Mod;
74 ans%=Mod;
75 }
76 cout<<ans;
77 }