description: You are given an array of n positive integers a_1, a_2, …, a_n. Your task is to calculate the number of arrays of n positive integers b_1, b_2, …, b_n such that: 
  
    * 1 ≤ b_i ≤ a_i for every i (1 ≤ i ≤ n), and 
    * b_i ≠ b_{i+1} for every i (1 ≤ i ≤ n - 1). 
  
  
  
  The number of such arrays can be very large, so print it modulo 998 244 353.
  
  Input
  
  The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the array a.
  
  The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9).
  
  Output
  
  Print the answer modulo 998 244 353 in a single line.
  
  Examples
  
  Input
  
  
  3
  2 2 2
  
  
  Output
  
  
  2
  
  Input
  
  
  2
  2 3
  
  
  Output
  
  
  4
  
  Input
  
  
  3
  1 1 1
  
  
  Output
  
  
  0
  
  Note
  
  In the first test case possible arrays are [1, 2, 1] and [2, 1, 2].
  
  In the second test case possible arrays are [1, 2], [1, 3], [2, 1] and [2, 3].
solution: #include <bits/stdc++.h>
  using namespace std;
  const long long MAXL = 1 << 22;
  char i_str[MAXL], o_str[MAXL], *i_s, *i_t;
  long long o_t;
  inline char gc() {
    if (i_s == i_t) {
      i_s = i_str;
      i_t = i_s + fread(i_str, 1, MAXL, stdin);
      return i_s == i_t ? EOF : *i_s++;
    } else
      return *i_s++;
  }
  inline long long read() {
    long long x = 0, f = 0;
    char ch = gc();
    for (; ch < '0' || ch > '9'; ch = gc())
      if (ch == '-') f = 1;
    for (; ch >= '0' && ch <= '9'; ch = gc()) x = x * 10 + (ch ^ 48);
    return f ? -x : x;
  }
  inline void pc(char x) {
    o_str[o_t++] = x;
    if (o_t == MAXL) fwrite(o_str, 1, o_t, stdout), o_t = 0;
  }
  void write(long long x) {
    if (x < 0) pc('-'), x = -x;
    if (x > 9) write(x / 10);
    pc(x % 10 ^ 48);
  }
  const long long N = 5e5 + 5, mod = 998244353;
  using namespace std;
  long long m, n, p, k, now = 1, tot, r = 0, Min[N], g[N], a[N], f[N];
  inline void TryInsert(long long x) {
    long long s = 0;
    while (r > 0) {
      if (Min[r] >= x)
        (s += (mod + 1ll * now * g[r]) % mod) %= mod,
            (tot += (mod - 1ll * now * g[r] * Min[r] % mod) % mod) %= mod, --r;
      else
        break;
    }
    Min[++r] = x;
    g[r] = (mod + 1ll * now * s) % mod;
    (tot += (mod + 1ll * now * g[r] * Min[r] % mod) % mod) %= mod;
    return;
  }
  inline void InsertItem(long long x) {
    (tot += (mod - 1ll * now * g[r] * Min[r] % mod) % mod) %= mod;
    (g[r] += (mod + x * now) % mod) %= mod;
    (tot += (mod + 1ll * now * g[r] * Min[r] % mod) % mod) %= mod;
    return;
  }
  inline long long Mini(long long x, long long y) {
    long long s = a[x];
    for (register long long i = x; i <= y; ++i) s = min(s, a[i]);
    return s;
  }
  signed main() {
    n = read();
    for (register long long i = 1; i <= n; ++i) a[i] = read();
    f[0] = 1;
    for (register long long i = 1; i <= n; ++i) {
      TryInsert(a[i]);
      f[i] = 1ll * f[i - 1] * a[i] % mod;
      (f[i] += tot) %= mod;
      InsertItem(f[i - 1]);
      now *= -1;
      tot = (mod - tot) % mod;
    }
    write(f[n] % mod), pc('\n'), fwrite(o_str, 1, o_t, stdout), o_t = 0;
    return 0;
  }
  