You have been hired by a Brazilian HFT (High Frequency Trading) company, which uses robots to buy and sell stocks on the stock exchange in fractions of a second in a fully systematic and automated way. Your first task is to implement a signal: a number, computed from the current state of the market, that guides the robot's decision between buying, selling, or doing nothing. The signal you will compute determines whether, at that moment, there is more buying demand or more selling supply for a stock.
On the exchange, whoever wants to buy or sell stocks registers an order in the order book. The book consists of two queues: buy orders and sell orders. Orders are grouped into price levels, ordered from best to worst. For each level $$$i$$$, you are given $$$c_i$$$ (total shares in buy orders) and $$$v_i$$$ (total shares in sell orders).
The signal measures the book's imbalance for the first $$$n$$$ levels: $$$$$$ I_n = \frac{C_n - V_n}{C_n + V_n}, \qquad \text{where } C_n = \sum_{i=1}^{n} c_i \text{ and } V_n = \sum_{i=1}^{n} v_i. $$$$$$
The value of $$$I_n$$$ always lies between $$$-1$$$ and $$$1$$$ and is interpreted as follows:
Given the order book and a series of queries, where the $$$j$$$-th query has depth $$$n_j$$$, report the signal corresponding to each query.
The first line contains an integer $$$N$$$ ($$$1 \leq N \leq 10^{5}$$$), the number of levels in the order book.
Each of the following $$$N$$$ lines contains two integers $$$c_i$$$ and $$$v_i$$$ ($$$0 \leq c_i, v_i \leq 10000$$$), respectively the total shares in the buy orders and sell orders at level $$$i$$$. It is guaranteed that $$$c_1 + v_1 \gt 0$$$.
The next line contains an integer $$$Q$$$ ($$$1 \leq Q \leq 10^{5}$$$), the number of queries. Each of the following $$$Q$$$ lines contains an integer $$$n_j$$$ ($$$1 \leq n_j \leq N$$$), the depth of the $$$j$$$-th query.
Your program must produce $$$Q$$$ lines. The $$$j$$$-th line must contain a single word: COMPRA if $$$I_{n_j} \gt 0$$$, VENDA if $$$I_{n_j} \lt 0$$$, or NEUTRO if $$$I_{n_j} = 0$$$.
410 21 90 78 141234
COMPRA NEUTRO VENDA NEUTRO
15 3211
COMPRA COMPRA
| Name |
|---|


