#P9050. [PA 2021] Sumy

[PA 2021] Sumy

Problem Description

There are nn fish, where the mass of the ii-th fish is aia_i grams.

Fish xx can eat fish yy if and only if ax>aya_x > a_y.

If xx eats yy, then yy disappears, and axa_x becomes ax+aya_x + a_y.

You may choose the order of eating freely until only one fish remains.

For each fish, determine whether it is possible for it to be the only fish left at the end. If it is impossible to end up with only one fish, then no fish satisfies this condition.

Input Format

The first line contains an integer nn.

The second line contains nn integers a1,a2,,ana_1, a_2, \cdots, a_n.

Output Format

Output one line containing a string ss of length nn, where si=Ts_i = \text{T} means the ii-th fish satisfies the condition above, and si=Ns_i = \text{N} means it does not.

6
2 7 1 8 2 8
NTNTNT
3
5 4 4
TNN

Hint

Sample #1 Explanation

Below, xyx \rightarrow y means that xx eats yy.

One possible sequence that leaves fish 22 is: $2 \rightarrow 1, 2 \rightarrow 3, 2 \rightarrow 4, 2 \rightarrow 5, 2 \rightarrow 6$.

Constraints

For 100%100\% of the testdata, 1n5×1051 \leq n \leq 5 \times 10^5, 1ai1091 \leq a_i \leq 10^9.

Translated by ChatGPT 5