#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define maxh 20000
constexpr int mod = 998244353;
vector<int> id[maxh + 1];
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, ans = 0;
cin >> n;
vector<int> h(n + 1);
for (int i = 1; i <= n; i++)
cin >> h[i], id[h[i]].push_back(i);
// 枚举公差
for (int d = -maxh; d <= maxh; d++)
{
// dp[i]表示以h[i]结尾有多少个公差为d的等差数列
vector<int> dp(n + 1, 1);
for (int i = 2; i <= n; i++)
{
int pre = h[i] - d;
if (pre < 0 || pre > maxh)
continue;
for (int j = 0; j < (int)id[pre].size() && id[pre][j] < i; j++)
dp[i] = (dp[i] + dp[id[pre][j]]) % mod;
}
for (int i = 1; i <= n; i++)
ans = (ans + dp[i]) % mod;
}
// 这行代码的意义是什么
ans = (ans + mod - 2 * maxh * n) % mod;
cout << ans << '\n';
return 0;
}
为什么有了这行就对了 ans = (ans + mod - 2 * maxh * n) % mod;