#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
#define lowbit(x) x&(-x)
#define maxn 300010
#define pp 19260817
#define ll long long
ll tree[maxn],tree2[maxn],a[maxn],n;
long long ans;
vector<ll> b;
void update(ll u,ll c)
{
for(ll i=u;i<=n;tree[i]+=c,tree[i]%=pp,i+=lowbit(i));
}
void update2(ll u,ll c)
{
for(ll i=u;i<=n;tree2[i]+=c,tree2[i]%=pp,i+=lowbit(i));
}
ll query(ll u)
{
ll sum=0;
for(ll i=u;i>0;sum+=tree[i],sum%=pp,i-=lowbit(i));
return sum;
}
ll query2(ll u)
{
ll sum=0;
for(ll i=u;i>0;sum+=tree2[i],sum%=pp,i-=lowbit(i));
return sum;
}
int main()
{
scanf("%lld",&n);
for(ll i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
a[i]%=pp;
b.push_back(a[i]);
}
sort(b.begin(),b.end());
b.erase(unique(b.begin(),b.end()),b.end());
for(ll i=1;i<=n;i++)
a[i]=lower_bound(b.begin(),b.end(),a[i])-b.begin()+1;
update(a[1],b[a[1]-1]);
update(a[2],b[a[2]-1]);
if(a[1]<a[2])
update2(a[2],b[a[1]-1]*b[a[2]-1]%pp);
for(ll i=3;i<=n;i++)
{
ans+=b[a[i]-1]*query2(a[i]-1);
ans%=pp;
update(a[i],b[a[i]-1]%pp);
update2(a[i],query(a[i]-1)*b[a[i]-1]%pp);
}
printf("%lld\n",ans);
}