#include <bits/stdc++.h>
using namespace std;
constexpr int INF = (numeric_limits<int>::max()) / 2;
constexpr long long INFLL = (numeric_limits<long long>::max()) / 2;
template <class T>
istream &operator>>(istream &is, vector<T> &a) {
  for (auto &i : a) {
    is >> i;
  }
  return is;
}
constexpr int mod = 998244353;
struct segtree {
  struct line {
    int k = -INF, b = -INF;
    line() = default;
    line(int k, int b) : k(k), b(b){};
    bool operator==(line p) const { return k == p.k && b == p.b; }
  };
  struct Node {
    int sum = 0;
    line push;
    Node *l = nullptr, *r = nullptr;
    Node() = default;
  };
  Node *root = nullptr;
  int n = 1e9 + 1;
  void creatend(Node *&v) {
    if (v == nullptr) {
      v = new Node();
    }
  }
  void push(Node *v, int l, int r) {
    if (v->push == line()) {
      return;
    }
    if (l + 1 < r) {
      creatend(v->l);
      if (v->l->push == line()) {
        v->l->push = v->push;
      } else {
        v->l->push = {
            (int)((v->push.k * 1ll * v->l->push.k) % mod),
            (int)((v->push.k * 1ll * v->l->push.b + v->push.b) % mod)};
      }
      creatend(v->r);
      if (v->r->push == line()) {
        v->r->push = v->push;
      } else {
        v->r->push = {
            (int)((v->push.k * 1ll * v->r->push.k) % mod),
            (int)((v->push.k * 1ll * v->r->push.b + v->push.b) % mod)};
      }
    }
    v->sum = (v->sum * 1ll * v->push.k) % mod;
    v->sum = (v->sum + (r - l) * 1ll * v->push.b) % mod;
    v->sum = (v->sum + mod) % mod;
    v->push = line();
  }
  void update(Node *&v, int l, int r, int li, int ri, line f) {
    creatend(v);
    push(v, l, r);
    if (li >= r || l >= ri) {
      return;
    }
    if (li <= l && r <= ri) {
      v->push = f;
      push(v, l, r);
      return;
    }
    int m = (l + r) / 2;
    update(v->l, l, m, li, ri, f);
    update(v->r, m, r, li, ri, f);
    v->sum = (v->l->sum + v->r->sum) % mod;
  }
  void update(int li, int ri, line f) { update(root, 1, n, li, ri, f); }
  int get() {
    creatend(root);
    push(root, 1, n);
    return root->sum;
  }
};
signed main() {
  cin.tie(0)->sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  segtree t;
  t.update(1, a[0] + 1, {0, 1});
  for (int i = 1; i < n; ++i) {
    int sum = t.get();
    t.update(1, a[i] + 1, {-1, sum});
    t.update(a[i] + 1, t.n, {0, 0});
  }
  cout << t.get();
}

### Prompt

Your challenge is to write a cpp solution to the following problem:

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;
constexpr int INF = (numeric_limits<int>::max()) / 2;
constexpr long long INFLL = (numeric_limits<long long>::max()) / 2;
template <class T>
istream &operator>>(istream &is, vector<T> &a) {
  for (auto &i : a) {
    is >> i;
  }
  return is;
}
constexpr int mod = 998244353;
struct segtree {
  struct line {
    int k = -INF, b = -INF;
    line() = default;
    line(int k, int b) : k(k), b(b){};
    bool operator==(line p) const { return k == p.k && b == p.b; }
  };
  struct Node {
    int sum = 0;
    line push;
    Node *l = nullptr, *r = nullptr;
    Node() = default;
  };
  Node *root = nullptr;
  int n = 1e9 + 1;
  void creatend(Node *&v) {
    if (v == nullptr) {
      v = new Node();
    }
  }
  void push(Node *v, int l, int r) {
    if (v->push == line()) {
      return;
    }
    if (l + 1 < r) {
      creatend(v->l);
      if (v->l->push == line()) {
        v->l->push = v->push;
      } else {
        v->l->push = {
            (int)((v->push.k * 1ll * v->l->push.k) % mod),
            (int)((v->push.k * 1ll * v->l->push.b + v->push.b) % mod)};
      }
      creatend(v->r);
      if (v->r->push == line()) {
        v->r->push = v->push;
      } else {
        v->r->push = {
            (int)((v->push.k * 1ll * v->r->push.k) % mod),
            (int)((v->push.k * 1ll * v->r->push.b + v->push.b) % mod)};
      }
    }
    v->sum = (v->sum * 1ll * v->push.k) % mod;
    v->sum = (v->sum + (r - l) * 1ll * v->push.b) % mod;
    v->sum = (v->sum + mod) % mod;
    v->push = line();
  }
  void update(Node *&v, int l, int r, int li, int ri, line f) {
    creatend(v);
    push(v, l, r);
    if (li >= r || l >= ri) {
      return;
    }
    if (li <= l && r <= ri) {
      v->push = f;
      push(v, l, r);
      return;
    }
    int m = (l + r) / 2;
    update(v->l, l, m, li, ri, f);
    update(v->r, m, r, li, ri, f);
    v->sum = (v->l->sum + v->r->sum) % mod;
  }
  void update(int li, int ri, line f) { update(root, 1, n, li, ri, f); }
  int get() {
    creatend(root);
    push(root, 1, n);
    return root->sum;
  }
};
signed main() {
  cin.tie(0)->sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  segtree t;
  t.update(1, a[0] + 1, {0, 1});
  for (int i = 1; i < n; ++i) {
    int sum = t.get();
    t.update(1, a[i] + 1, {-1, sum});
    t.update(a[i] + 1, t.n, {0, 0});
  }
  cout << t.get();
}

```