MIPS | Malaysian Informatics And Programming Society

Increasing Subsequence Median Sum

Statement

Evirir the dragon has a sequence of integers A=[A1,A2,,AN]A = [A_1, A_2, \ldots, A_N] and many definitions below.

A sequence BB is a subsequence of a sequence AA if BB can be obtained from AA by the deletion of several (possibly zero or all) elements from arbitrary positions. Two subsequences are considered different if the sets of positions of the deleted elements are different.

A subsequence B=[B1,B2,,Bk]B = [B_1, B_2, \ldots, B_k] is strictly increasing if for all ii where 1ik11 \leq i \leq k - 1, Bi<Bi+1B_i < B_{i+1}.

A subsequence B=[B1,B2,,Bk]B = [B_1, B_2, \ldots, B_k] of AA is good if BB has odd length (kk is odd) and BB is strictly increasing.

The median of a good subsequence is the element in the middle of the subsequence. Formally, if B=[B1,B2,...,Bk]B = [B_1, B_2, ..., B_k] is a good subsequence, the median of BB is B(k+1)/2.B_{(k+1)/2}.

Find the sum of the medians of all the good subsequences of AA modulo 998244353998\,244\,353.

Note: Modulo means “taking the remainder of”. For example, 15 modulo 6 is 3, 2 modulo 5 is 2, and 4 modulo 2 is 0. For this problem, you have to output the remainder of the answer after dividing by 998244353998\,244\,353.

Input Format

The first line contains a single integer NN.

The second line contains NN space-separated integers A1,A2,,ANA_1, A_2, \ldots, A_N.

Output Format

Output one integer, the sum of the medians of all good subsequences modulo 998244353998\,244\,353.

Constraints

For all tasks:

Sample Input

4
1 2 4 3

Sample Output

14

Sample Explanation

The sequence A=[1,2,4,3]A = [1,2,4,3] has six good subsequences:

Therefore, the answer is 1+2+4+3+2+2=141+2+4+3+2+2=14.

The following are some examples of subsequences that are not good.


Jumlah Median Subsekuens Meningkat (Increasing Subsequence Median Sum)

Pernyataan

Evirir si naga mempunyai satu jujukan integer A=[A1,A2,,AN]A = [A_1, A_2, \ldots, A_N] dan beberapa takrifan berikut.

Satu jujukan BB ialah subjujukan kepada jujukan AA jika BB boleh diperoleh daripada AA dengan memadamkan beberapa (mungkin sifar atau semua) elemen pada kedudukan yang sewenang-wenangnya. Dua subjujukan dianggap berbeza jika set bagi kedudukan bagi elemen yang dipadam adalah berbeza.

Subjujukan B=[B1,B2,,Bk]B = [B_1, B_2, \ldots, B_k] dikatakan meningkat tegas (strictly increasing) jika bagi semua ii dengan 1ik11 \leq i \leq k - 1, Bi<Bi+1B_i < B_{i+1}.

Subjujukan B=[B1,B2,,Bk]B = [B_1, B_2, \ldots, B_k] bagi AA dipanggil baik jika panjang BB adalah ganjil (kk ganjil) dan BB meningkat tegas.

Median bagi subjujukan baik ialah elemen di tengah-tengah subjujukan. Secara formalnya, jika B=[B1,B2,...,Bk]B = [B_1, B_2, ..., B_k] ialah subjujukan baik, maka median BB ialah B(k+1)/2B_{(k+1)/2}.

Cari jumlah median bagi semua subsekuens baik A, modulo 998244353998\,244\,353.

Nota: Modulo bermaksud “ambil baki hasil bahagi”. Contohnya, 15 modulo 6 ialah 3, 2 modulo 5 ialah 2, dan 4 modulo 2 ialah 0. Dalam masalah ini, anda perlu keluarkan baki jawapan selepas dibahagi dengan 998244353998\,244\,353.

Format Input

Baris pertama mengandungi satu integer NN. Baris kedua mengandungi NN integer yang dipisahkan oleh ruang: A1,A2,,ANA_1, A_2, \ldots, A_N.

Format Output

Keluarkan satu integer, iaitu jumlah median semua subsekuens baik modulo 998244353998\,244\,353.

Kekangan

Untuk semua tugasan:

Contoh Input

4
1 2 4 3

Contoh Output

14

Penjelasan Contoh

Tatasusunan A=[1,2,4,3]A = [1,2,4,3] mempunyai enam subsekuens baik:

Oleh itu, jawapan ialah 1+2+4+3+2+2=141+2+4+3+2+2 = 14.

Contoh subsekuens yang bukan baik:


递增子序列中位数之和

题目描述

龙 Evirir 有一个整数序列 A=[A1,A2,,AN]A = [A_1, A_2, \ldots, A_N],以及以下若干定义。

若序列 BB 可以通过从序列 AA 中删除若干个(可能为零个或全部)任意位置的元素得到,则称 BBAA 的一个子序列。两个子序列被认为是不同的当且仅当被删除元素的位置集合不同。

若子序列 B=[B1,B2,,Bk]B = [B_1, B_2, \ldots, B_k] 对所有 1ik11 \leq i \leq k - 1,都满足 Bi<Bi+1B_i < B_{i+1},则称 BB 为一个严格递增子序列

若子序列 B=[B1,B2,,Bk]B = [B_1, B_2, \ldots, B_k] 的长度是奇数(即 kk 是奇数)且 BB 是严格递增子序列 则称 BB 为一个子序列。

一个子序列的中位数定义为该子序列中位于中间位置的元素。另一句话,若 B=[B1,B2,,Bk]B = [B_1, B_2, \ldots, B_k] 是一个好子序列,则其中位数为 B(k+1)/2B_{(k+1)/2}

求所有 AA子序列的中位数之和,并将答案对 998244353998\,244\,353 取模。

注意:取模(modulo)表示“取余数”。例如,15 对 6 取模为 3,2 对 5 取模为 2,4 对 2 取模为 0。对于本题,请输出答案除以 998244353998\,244\,353 的余数。

输入格式

第一行包含一个整数 NN

第二行包含 NN 个用空格分隔的整数 A1,A2,,ANA_1, A_2, \ldots, A_N

输出格式

输出一个整数——所有好子序列的中位数之和对 998244353998\,244\,353 取模后的结果

约束

对于每项任务:

样例输入

4
1 2 4 3

样例输出

14

样例解释

序列 A=[1,2,4,3]A = [1,2,4,3] 有六个好子序列:

答案是 1+2+4+3+2+2=141+2+4+3+2+2=14

以下是一些不好子序列的例子。