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
#include <bits/stdc++.h>
#define FOR(i,n) for(int i = 0; i<n; ++i)
#define FOREACH(v, a) for(auto & v : (a))
#define X first
#define Y second
#define PR std::pair
#define MPR std::make_pair
typedef long long ll;
typedef std::vector<int> VI;

using namespace std;

#pragma region Ready functions

int fastPower(int a, int b){
    int res=1, pop_a = a;
    while(b){
        if(b&1) res *= pop_a;
        pop_a *= pop_a;
        b>>=1;
    }
    return res;
}

#pragma endregion

vector<pair<ll,int>> nums;
map<int, ll> sums;
bool king[500001];

void CalculateSums(){
    int lastNum = -1;
    int currentNum = nums[0].first;
    sums[nums[0].first] = nums[0].first;

    for(int i = 1; i<nums.size(); i++){
        if(currentNum != nums[i].first){
            sums[nums[i].first] = sums[currentNum] + nums[i].first;
            currentNum = nums[i].first;
            continue;
        }
        
        sums[currentNum] += currentNum;
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    int n;

    cin>>n;

    ll minimum = 99999999999;
    ll maksimum = 0;

    for(int i = 0; i<n; i++){
        ll x;
        cin>>x;
        nums.push_back({x, i});
        minimum = min(minimum, x);
        maksimum = max(maksimum, x);
    }

    if(minimum == maksimum){
        FOR(i, n) cout<<'N';
        return 0;
    }

    sort(nums.begin(), nums.end());

    CalculateSums();

    int lastNum = maksimum;
    int currentNum = maksimum;

    bool failing = true;

    for(int i = n-1; i>=0; i--){

        if(nums[i].first < currentNum){
            lastNum = currentNum;
            currentNum = nums[i].first;
        }

        if(nums[i].first == minimum) failing = false;
        else{

            //get the sum of all elements <= x
            //and check if its bigger than the next
            if(sums[currentNum] <= lastNum){
                king[nums[i].second] = false;
                failing = false;
            }
        }

        king[nums[i].second] = failing;

        //cout<<currentNum<<" "<<sums[currentNum]<<endl;
    }

    for(int i = 0; i<n; i++){
        
        cout<<(king[i] == 0 ? 'N' : 'T');
    }



    
}