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
#include <bits/stdc++.h>
#include <iostream>
#include <vector>

using namespace std;

bool is_a_king(vector<int>& v, vector<int>& partial_sums, int index) {
    int i = index;
    while (i - 1 >= 0 && v[i - 1] == v[index]) {
        i--;
    }
    if (i == 0 && v[0] == v[index]) {
        return false;
    } else {

        int p = partial_sums[i];
        i++;
        while (i < v.size() && p > v[i]) {     
            p = partial_sums[i];
            i++;
        }
        bool result = (i == v.size() ? true : false);
        //cout << "is_a_king: " << index << " = " << result << endl;
        return result;
    }
}

void solve(vector<int>& v) {
    vector<int> orig_v = v;
    vector<int> partial_sums(v.size());

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

    partial_sums[0] = v[0];
    for (int i = 1; i < v.size(); i++) {
        partial_sums[i] = v[i] + partial_sums[i - 1];
    }

    /*for (int i = 0; i < v.size(); i++) {
        cout << v[i] << ", ";
    }
    cout << endl;
    for (int i = 0; i < v.size(); i++) {
        cout << partial_sums[i] << ", ";
    }
    cout << endl;*/

    int left = 0;
    int right = v.size() - 1;

    while (left < right) {
        int mid = (left + right) / 2;
        int orig_mid = mid;
        while (mid - 1 >= 0 && v[mid - 1] == v[orig_mid]) {
            mid--;
        }
        //cout << "mid = " << mid << ", " << left << ", " << right << endl;
        if (is_a_king(v, partial_sums, mid)) {
            right = orig_mid - 1;
        } else {
            left = orig_mid + 1;
        }
    }

    int king_value = -1;
    for (int i = left - 3; i <= left + 3; i++) {
        if (i >= 0 && i < v.size() && is_a_king(v, partial_sums, i)) {
            king_value = v[i];
            break;
        }
    }

    /*int king_value = -1;
    for (int i = 0; i < v.size(); i++) {
        if (is_a_king(v, partial_sums, i)) {
            king_value = v[i];
            break;
        }
    }*/

    //cout << king_value << endl;

    for (int i = 0; i < v.size(); i++) {
        if (king_value == -1 || orig_v[i] < king_value) {
            cout << "N";
        } else {
            cout << "T";
        }
    }    
}

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

    int n;
    
    cin >> n;

    vector<int> v(n, 0);

    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }

    if (v.size() == 1) {
        cout << "T";
        return 0;
    }

    solve(v);

    return 0;
}