PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#CC0000048. Đếm dãy con có đầu không lớn hơn cuối (LEQ)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Đếm dãy con có đầu không lớn hơn cuối (LEQ)

LEQ

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Given an integer sequence aa, count not necessarily contiguous subsequences of length at least 2 whose first element is at most the last element. Different index sets count separately. Print modulo 998244353998244353.

Input

The first line contains nn. The second line contains nn integers aia_i.

Output

Print the result modulo 998244353998244353.

Subtasks

  • Subtask 1 (20 points): 2≤n≤122\le n\le 12; 1≤ai≤1091\le a_i\le10^9.
  • Subtask 2 (30 points): 2≤n≤4202\le n\le 420; 1≤ai≤1091\le a_i\le10^9.
  • Subtask 3 (50 points): 2≤n≤3000002\le n\le 300000; 1≤ai≤1091\le a_i\le10^9.

Examples

Input

3
1 2 1

Output

3

Explanation

Valid index selections are (1,2), (1,3) and (1,2,3). Selection (2,3) fails since 2 is greater than 1.