#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  char ch = getchar();
  bool f = 0;
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = 1;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    x = (x << 3) + (x << 1) + (ch ^ 48);
  return f ? -x : x;
}
const long long mod = 998244353;
inline long long Add(long long x, long long y) {
  x += y;
  return (x < mod) ? x : x - mod;
}
inline long long Dec(long long x, long long y) {
  x -= y;
  return (x < 0) ? x + mod : x;
}
inline long long Mul(long long x, long long y) { return x * y % mod; }
inline long long Pow(long long x, long long y) {
  y %= (mod - 1);
  long long ans = 1;
  for (; y; y >>= 1, x = x * x % mod)
    if (y & 1) ans = ans * x % mod;
  return ans;
}
const int N = 5e5 + 5;
int n, a[N];
long long s[N], f[N];
int st[N], top;
int main() {
  n = read();
  for (int i = (1), end_i = (n); i <= end_i; i++) a[i] = read();
  s[0] = 1;
  f[0] = 1;
  long long now = 0;
  for (int i = (1), end_i = (n); i <= end_i; i++) {
    for (; top && a[st[top]] > a[i]; top--)
      now = Dec(now, Dec(s[st[top] - 1], st[top - 1] ? s[st[top - 1] - 1] : 0) *
                         a[st[top]] % mod);
    now = Add(now, Dec(s[i - 1], st[top] ? s[st[top] - 1] : 0) * a[i] % mod);
    st[++top] = i;
    f[i] = (mod - now) % mod;
    s[i] = Add(s[i - 1], f[i]);
  }
  printf("%lld\n", f[n] * Pow(mod - 1, n) % mod);
  return 0;
}

### Prompt

Develop a solution in Cpp to the problem described below:

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].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  char ch = getchar();
  bool f = 0;
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = 1;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    x = (x << 3) + (x << 1) + (ch ^ 48);
  return f ? -x : x;
}
const long long mod = 998244353;
inline long long Add(long long x, long long y) {
  x += y;
  return (x < mod) ? x : x - mod;
}
inline long long Dec(long long x, long long y) {
  x -= y;
  return (x < 0) ? x + mod : x;
}
inline long long Mul(long long x, long long y) { return x * y % mod; }
inline long long Pow(long long x, long long y) {
  y %= (mod - 1);
  long long ans = 1;
  for (; y; y >>= 1, x = x * x % mod)
    if (y & 1) ans = ans * x % mod;
  return ans;
}
const int N = 5e5 + 5;
int n, a[N];
long long s[N], f[N];
int st[N], top;
int main() {
  n = read();
  for (int i = (1), end_i = (n); i <= end_i; i++) a[i] = read();
  s[0] = 1;
  f[0] = 1;
  long long now = 0;
  for (int i = (1), end_i = (n); i <= end_i; i++) {
    for (; top && a[st[top]] > a[i]; top--)
      now = Dec(now, Dec(s[st[top] - 1], st[top - 1] ? s[st[top - 1] - 1] : 0) *
                         a[st[top]] % mod);
    now = Add(now, Dec(s[i - 1], st[top] ? s[st[top] - 1] : 0) * a[i] % mod);
    st[++top] = i;
    f[i] = (mod - now) % mod;
    s[i] = Add(s[i - 1], f[i]);
  }
  printf("%lld\n", f[n] * Pow(mod - 1, n) % mod);
  return 0;
}

```