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
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <vector>

using namespace std;

class fish {
public:
        char king;
        long long w;
        long long s;
        int pos;
};

bool cmpfish(fish i, fish j) { return (i.w<j.w); }
bool cmpfish2(fish i, fish j) { return (i.pos<j.pos); }

vector<fish> v;
int n;

void print()
{
        for(auto f : v) {
                printf("(pos %d) w:%lld s:%lld k:%c\n", f.pos, f.w, f.s, f.king);
        }
}

void print_result()
{
        sort(v.begin(), v.end(), cmpfish2);
        for(auto f : v) {
                printf("%c", f.king);
        }
        printf("\n");
}

void calc_s()
{
        v[0].s = v[0].w;
        for(int i = 1; i < n; ++i) {
                v[i].s = v[i-1].s + v[i].w;
        }
}

void calc_king()
{
        int i, j, k;

        v[0].king = 'N';
        i = 1;
        while(i < n && v[i].w == v[0].w) {
                v[i].king = 'N';
                i++;
        }
        if (i == n) {
                return;
        }
        k = i;

        v[n-1].king = 'T';
        i = n-2;
        while(i >= 0 && v[i].w == v[n-1].w) {
                v[i].king = 'T';
                i--;
        }
        j = i+1;

        for(i = k; i < j; ++i) {
//                if (v[i].w == v[i-1].w && v[i-1].king == 'N') {
//                        v[i].king = 'N';
//                        continue;
//                }
                if (v[i].s <= v[i+1].w) {
                        v[i].king = 'N';
                }
        }
        i = n-2;
        while(i >= 0 && v[i].king != 'N') {
                v[i].king = 'T';
                i--;
        }
        while(i >= 0) {
                v[i].king = 'N';
                i--;
        }
}

int main()
{
        scanf("%d\n", &n);
        for(int i = 0; i < n; ++i) {
                fish f;
                int w;

                scanf("%d\n", &w);
                f.w = w;
                f.pos = i;
                f.king = '?';
                v.push_back(f);
        }

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

        calc_s();
        calc_king();
//        print();
        print_result();

        return 0;
}