Under construction

Still being built. Things may change

Bruteforce

Time limit5sMemory limit512 MB

Summary
After each point update to an array, report the sum over sorted values of floor(b_i * i^k / w), with k and w at most 5, modulo 998244353.
Level

Medium6 of 10

Topics
Sorting, Brute force, Implementation, Math
Solved
No attempts yet

Problem

You are given fixed integers kk and ww.

For an array aa of length nn, its weight is defined as follows.

  • Let bb be the array aa sorted in non-descending order.
  • The weight of aa is ∑i=1n⌊bi⋅ikw⌋\displaystyle \sum_{i=1}^{n} \left\lfloor{\frac{b_i \cdot i^k}{w}}\right\rfloor.

Here, ⌊x⌋\left\lfloor x \right\rfloor is the largest integer not exceeding xx.

For example, if k=2k = 2 and w=3w = 3, then the weight of a=[3,2,2]a = [3, 2, 2] is

⌊2⋅123⌋+⌊2⋅223⌋+⌊3⋅323⌋=0+2+9=11\displaystyle \left\lfloor {\frac{2 \cdot 1^2}{3}} \right\rfloor + \left\lfloor {\frac{2 \cdot 2^2}{3}} \right\rfloor + \left\lfloor {\frac{3 \cdot 3^2}{3}} \right\rfloor = 0 + 2 + 9 = 11.

You are given an initial array aa, and then qq queries. Each query changes one element of array aa. After each query, output the new weight of the array. Array weights can be very large, so output them modulo 998 244 353998\,244\,353.

Changes persist between queries. For example, the second query is applied to the array already changed by the first query.

Input

The first line contains three integers nn, kk, ww (1≤n≤1051 \le n \le 10^5, 1≤k≤51 \le k \le 5, 1≤w≤51 \le w \le 5): the length of the array and the parameters from the statement.

The second line contains nn integers aia_i (0≤ai≤1050 \le a_i \le 10^5): the elements of the original array.

The third line contains a single integer qq (1≤q≤1051 \le q \le 10^5): the number of queries.

Each of the next qq lines contains two integers pos\mathit{pos} and xx (1≤pos≤n1 \le \mathit{pos} \le n, 0≤x≤1050 \le x \le 10^5). This describes a query that changes aposa_{\mathit{pos}} into xx.

Output

Output qq integers: the weight of the array after each change, modulo 998 244 353998\,244\,353.

Examples2

  1. Example 1

    Input
    3 1 1
    2 2 8
    2
    2 5
    3 6
    
    Expected output
    36
    30
    
  2. Example 2

    Input
    4 2 2
    1 3 3 7
    4
    1 1
    2 4
    3 8
    4 8
    
    Expected output
    75
    80
    103
    108