Under construction

Still being built. Things may change

Morty Buys Groceries

Time limit6sMemory limit1024 MB

Summary
Given n product costs, count ordered sequences of k products whose total cost lies between l and r for each query, modulo 786433.
Level

Medium7 of 10

Topics
Math, Prefix sum, Implementation
Solved
No attempts yet

Problem

Rick and Morty went to a store. As you may have figured out, Rick loves giving Morty all kinds of tasks, and this time is no exception. He needs Morty to count the ways to buy kk products. The store has nn products in total, and the cost of the ii-th product is cic_i. Rick will give Morty two numbers ll and rr a total of qq times. For each pair, Morty must say how many ways there are to buy kk products whose total cost is at least ll and at most rr.

A purchase is written as a set of indices {i1,i2,…,ik}\{i_1, i_2, \dots, i_k\}, where iji_j is the number of the product bought jj-th. Two purchases AA and BB are different if there is an index dd such that Ad≠BdA_d \neq B_d. So (1,2)(1, 2) and (2,1)(2, 1) are two different ways to buy. Also, one product can be bought any number of times.

Input

The first line contains three integers nn, kk, qq (1≤n,q≤1051 \leq n, q \leq 10^5, 1≤k≤1051 \leq k \leq 10^5). The second line contains nn integers cic_i, the costs of the products (1≤ci≤5⋅1041 \leq c_i \leq 5 \cdot 10^4). Each of the next qq lines contains two integers ll and rr (1≤l≤r≤5⋅1041 \leq l \leq r \leq 5 \cdot 10^4).

Output

Print the answers to Rick's qq queries, one per line. Since the answer can be very large, print it modulo 786433786433.

Examples2

  1. Example 1

    Input
    5 1 5
    1 2 3 4 5
    1 2
    1 3
    1 4
    1 5
    2 5
    
    Expected output
    2
    3
    4
    5
    4
    
  2. Example 2

    Input
    2 2 1
    1 1
    1 10000
    
    Expected output
    4