#include<bits/stdc++.h>
using namespace std;
long long dp[390290];int s[301203],xc;
int h[300000];
long long sum;
int jj(int x)
{
if(x>=0)
return x+jj(x-1);
}
int main()
{
std::ios::sync_with_stdio(false);
dp[0]=1;
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>s[i];
h[s[i]]++;
dp[i]=1;
}
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
xc=s[i];
int c=s[j]-s[i];
int z=0;
if(c==0)
{
dp[i]+=jj(h[s[i]]);
}
// cout<<s[i]<<endl;
while(xc+c>=0&&h[xc+c]>=1&&c!=0)
{
z++;
xc=xc+c;//cout<<xc<<',';
}
dp[i]+=z;
// cout<<endl;
}
sum+=dp[i];
}
cout<<sum%998244353;
return 0;
}