1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <algorithm>

using namespace std;

struct sum
{
    int *ans;
    int size;
};

void quick_sort(sum tab[], int lewy, int prawy)
{
    if (prawy <= lewy) return;

    int i = lewy - 1, j = prawy + 1,
        pivot = tab[(lewy + prawy) / 2].size;

    while (1)
    {
        while (pivot > tab[++i].size);

        while (pivot < tab[--j].size);

        if (i <= j)
            swap(tab[i], tab[j]);
        else
            break;
    }

    if (j > lewy)
        quick_sort(tab, lewy, j);
    if (i < prawy)
        quick_sort(tab, i, prawy);
}

int main()
{
    int n;
    sum sumy[500001];
    int* ans = new int[500001];
    int number;

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> number;
        sumy[i].ans = &ans[i];
        sumy[i].size = number;
    }
    quick_sort(sumy, 0, n-1);

    for (int i = 0; i < n; i++)
    {
        unsigned long long suma = sumy[i].size;
        int j = 0;
        while (suma > sumy[j].size && j < n)
        {
            if (j != i)
                suma += sumy[j].size;
            suma %= 1000000000;
            j++;
        }
        if (j == n)
            *sumy[i].ans = true;
    }

    for (int i = 0; i < n; i++)
    {
        if (ans[i] == true)
            cout << "T";
        else
            cout << "N";
    }

    return 0;
}