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$$$.
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)$$$.
1 1643212363
1
1 1279118545
1