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
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//
//  main.cpp
//  Suma2.0
//
//  Created by Andy Bachleda-Curuś on 09/12/2021.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>


using namespace std;

bool czy_p(int b, int e, int m, long long sum,  vector <long long> v)
{
    long long test = v[m - 1];
    for(int i = 0; i < m - 1; i++)
    {
        if(v[i] < test)
        {
            test += v[i];
        }
    }
    for(int i = m; i < v.size(); i++)
    {
        if(test > v[i])
        {
            test += v[i];
        }
        else{
            break;
        }
    }
    if(test == sum)
    {
        return true;
    }
    else
        return false;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector <long long> v(n);
    long long sum = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> v[i];
        sum += v[i];
    }
    if(n == 1)
    {
        cout << "T";
        return 0;
    }
    int p = 0, e = n;
    vector <long long> v_copy = v;
    sort(v_copy.begin(), v_copy.end());
    long long wyn = INT_MAX;
    int k = 0;
    while(k < v_copy.size())
    {
        int m = (p + e) / 2;
        //if(e - 1 == p)
         //   return p;
        long long test = v_copy[m];
        bool czy = true;
        int it = m;
        while(v_copy[it] == v_copy[it + 1] && it < v_copy.size())
        {
            it++;
        }
        for(int i = 0; i < it; i++)
        {
            if(v_copy[i] < test)
            {
                test += v_copy[i];
            }
            else{
                czy = false;
            }
        }
        if(czy == true)
        {
            for(int i = it + 1; i < v_copy.size(); i++)
            {
                if(test > v_copy[i])
                {
                    test += v_copy[i];
                }
                else{
                    czy = false;
                    break;
                }
            }
        }
        if(czy == true)
        {
            if(czy_p(p, e, m, sum, v_copy))
            {
                e = m;
            }
            else{
                wyn = v_copy[m];
                break;
            }
        }
        else{
            p = m;
        }
        k++;
    }
    for(int i = 0; i < n; i++)
    {
        if(v[i] >= wyn)
        {
            cout << "T";
        }
        else
        {
            cout << "N";
        }
    }
    cout << endl;
    
    return 0;
}