import java.io.*;
import java.util.*;

public class Main {
    static final int MOD = 998244353;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int[] values = new int[n];
        TreeMap<Integer, Integer> compress = new TreeMap<>();
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
            compress.put(values[i], null);
        }
        int idx = 1;
        for (int x : compress.keySet()) {
            compress.put(x, idx++);
        }
        BinaryIndexedTree firstValue = new BinaryIndexedTree(idx);
        BinaryIndexedTree firstCount = new BinaryIndexedTree(idx);
        BinaryIndexedTree secondValue = new BinaryIndexedTree(idx);
        BinaryIndexedTree secondCount = new BinaryIndexedTree(idx);
        long ans = 0;
        for (int i = n - 1; i >= 0; i--) {
            int v = compress.get(values[i]);
            ans += secondValue.getSum(v - 1) + secondCount.getSum(v - 1) * (long)values[i];
            ans %= MOD;
            long add = firstValue.getSum(v - 1) + firstCount.getSum(v - 1) * (long)values[i];
            secondValue.add(v, (int)(add % MOD));
            secondCount.add(v, firstCount.getSum(v - 1));
            firstValue.add(v, values[i]);
            firstCount.add(v, 1);
        }
        System.out.println(ans);
    }
    
}
class BinaryIndexedTree {
    int size;
    int[] tree;
    static final int MOD = 998244353;
    public BinaryIndexedTree(int size) {
        this.size = size;
        tree = new int[size];
    }
    
    public void add(int idx, int value) {
        int mask = 1;
        while (idx < size) {
            if ((idx & mask) != 0) {
                tree[idx] += value;
                tree[idx] %= MOD;
                idx += mask;
            }
            mask <<= 1;
        }
    }
    
    public int getSum(int x) {
        int mask = 1;
        int ans = 0;
        while (x > 0) {
            if ((x & mask) != 0) {
                ans += tree[x];
                ans %= MOD;
                x -= mask;
            }
            mask <<= 1;
        }
        return ans;
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}