Изменения рейтингов за последние раунды временно удалены. Скоро они будут возвращены. ×
F. Fast LLMs
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

While working at Meta AI, Sebastian developed low-latency translation models for deployment on edge devices such as mobile phones or his pretty garbage ThinkPad L390. While developing these models, he got the task of programming the popular $$$softmax$$$ function, but there's a problem: Since these low-power devices lack floating-point support, all operations must be done with integers under a large prime $$$p$$$. The softmax function is defined as: $$$$$$softmax_{int}(x_i)=\frac{2^{x_i}}{\sum_{j=1}^{n} 2^{x_j}}$$$$$$ where $$$x$$$ is a vector of (in this case) integer inputs, the denominator is the sum of all the inputs in our batch, and $$$x_i$$$ is the input to our softmax function, which is also in our input batch with an index $$$i$$$. Since Sebastian's AI model will be deployed on thousands of edge devices, he needs an extremely efficient algorithm to help him compute this function. Can you help him?

Remember that, since we need only integer outputs, we can represent $$$softmax(x_i)$$$ as a rational fraction $$$\frac{P}{Q}$$$ with $$$Q \gt 0$$$. To give this answer, you should print a single integer $$$P\times Q^{-1} \mod p$$$. Assume $$$p = 10^9 + 7$$$.

Input
  • The first line contains two integers $$$n, i$$$ ($$$1 \leq n \leq 10^5, i \leq n$$$) — the number of inputs in the batch and the index $$$i$$$ of the input to our softmax function $$$x_i$$$.
  • The second line contains $$$n$$$ integers $$$x_1, x_2, \ldots, x_n$$$ ($$$1 \leq x_i \leq 10^9$$$), representing the input vector to our softmax function.
Output

Print a single integer — the modular softmax probability with the input $$$x_i$$$. Note that this probability must be expressed as a single integer in the form $$$P\times Q^{-1} \mod (10^9+7)$$$.

Examples
Input
1 1
643212363
Output
1
Input
1 1
279118545
Output
1